Пульт для Canon на Arduino — исходники


Выкладываю на всякий случай код своего пульта для фотоаппарата на основе Arduino.
Раз сегодня выходной, есть шансы его немного допилить..

Код создан на основе примеров по работе с LCD дисплеем, поэтому оставлю всё то, что написал автор примера..
Есть идея прицепить сюда Bluetooth, и потом цепануться хотя бы с компа, или, в идеале — с андроида.


//Sample using LiquidCrystal library
#include

/*******************************************************

This program will test the LCD panel and the buttons
Mark Bramwell, July 2010

********************************************************/

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5

const int ledPin = 11; // 13 – если будете использовать встроенный в Arduino светодиод

int state = 0;

char sel_pressed = 0;
char sel_was_pressed = 0;

const int Trig = 2;
const int Echo = 3;

char states[] = {‘delay’,’time’,’count’};

// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this…
}

void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print(«Time Int Count»); // print a simple message
Serial.begin(9600);
//pinMode(buttonPin, INPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
}

unsigned int time_us=0;

unsigned int distance_sm=0;

int sel_count = 0;
int time = 1;
int interval = 2;
int count = 1;

int int_pressed = 0;
int count_pressed = 0;
int time_pressed = 0;

int cur_time = 0;
int n = 0;

int out_func() {
lcd.setCursor(15,1);

if (cur_time — n * (time + interval) <= time) {
lcd.print(«+»);
digitalWrite(2, HIGH);
}
else {
digitalWrite(2, LOW);
lcd.print(«-«);
}
n = cur_time / (time + interval);

lcd.print(n);

}

void loop()
{
lcd.setCursor(1,1); // move cursor to second line «1» and 9 spaces over
cur_time = millis()/1000; // display seconds elapsed since power-up

out_func();
//digitalWrite(2, HIGH);

//digitalWrite(3, HIGH);

//digitalWrite(1, LOW);

lcd_key = read_LCD_buttons();
lcd.setCursor(9,1);
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{

int_pressed ++ ;

if (int_pressed >= 50) {
interval ++;
int_pressed = 0;
}

lcd.setCursor(5,1);
lcd.print(» «);

lcd.setCursor(5,1);
lcd.print(interval);

break;
}
case btnLEFT:
{
int_pressed ++ ;
if (int_pressed >= 50) {
interval —;
int_pressed = 0;
if (interval == 0) interval = 5;
}
lcd.setCursor(5,1);
lcd.print(» «);

lcd.setCursor(5,1);
lcd.print(interval);
break;
}
case btnUP:
{

time_pressed ++ ;
if (time_pressed >= 50) {
time ++;
time_pressed = 0;
if (time == 0) time = 5;
}
lcd.setCursor(1,1);
lcd.print(» «);

lcd.setCursor(1,1);
lcd.print(time);

break;
}
case btnDOWN:
{
time_pressed ++ ;
if (time_pressed >= 50) {
time —;
time_pressed = 0;
if (time == 0) time = 5;
}
lcd.setCursor(1,1);
lcd.print(» «);

lcd.setCursor(1,1);
lcd.print(time);

break;
}
case btnSELECT:
{

sel_pressed ++ ;

if (sel_pressed >= 50) {
state ++;
sel_pressed =0;
if (state == 3) state =0;
}

//lcd.print(«Select»);
//lcd.setCursor(1,1);

break;

}

case btnNONE:
{

break;
}

}

}