Created
December 30, 2015 19:07
-
-
Save westonal/15a6391c4926f4a881ae to your computer and use it in GitHub Desktop.
Arduino Camera control via IR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <IRremote.h> | |
int RECV_PIN = 10; | |
int PIN_TAKE = 5; | |
int PIN_FOCUS = 2; | |
int PIN_TAKE_INDICATOR = 13; | |
#define Zero 0xFF6897 | |
#define One 0xFF30CF | |
long numerals[] = { | |
0xFF6897, //0 | |
0xFF30CF, //1 | |
0xFF18E7, //2 | |
0xFF7A85, //3 | |
0xFF10EF, //4 | |
0xFF38C7, //5 | |
0xFF5AA5, //6 | |
0xFF42BD, //7 | |
0xFF4AB5, //8 | |
0xFF52AD //9 | |
}; | |
#define key_plus100 0xFF9867 | |
#define key_plus200 0xFFB04F | |
#define key_minus 0xFFE01F | |
#define key_plus 0xFFA857 | |
#define key_eq 0xFF906F | |
#define key_ch_minus 0xFFA25D | |
#define key_channel 0xFF629D | |
#define key_ch_plus 0xFFE21D | |
#define key_previous 0xFF22DD | |
#define key_next 0xFF02FD | |
#define key_play_pause 0xFFC23D | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() | |
{ | |
Serial.begin(9600); | |
irrecv.enableIRIn(); // Start the receiver | |
pinMode(PIN_TAKE, OUTPUT); | |
pinMode(PIN_FOCUS, OUTPUT); | |
pinMode(PIN_TAKE_INDICATOR, OUTPUT); | |
} | |
int shutterMs = 100; | |
void take(int n) { | |
for(int i=0; i<n; i++) { | |
Serial.print("Take "); | |
Serial.print(i+1); | |
Serial.print(" of "); | |
Serial.println(n); | |
digitalWrite(PIN_TAKE, HIGH); | |
digitalWrite(PIN_TAKE_INDICATOR, HIGH); | |
delay(shutterMs); | |
digitalWrite(PIN_TAKE_INDICATOR, LOW); | |
digitalWrite(PIN_TAKE, LOW); | |
if (i < n-1) | |
delay(250); | |
} | |
} | |
void incShutter(int ms){ | |
shutterMs += ms; | |
Serial.print("Shutter: "); | |
Serial.println(shutterMs); | |
} | |
void focus(int ms){ | |
Serial.println("Focussing"); | |
digitalWrite(PIN_FOCUS, HIGH); | |
delay(ms); | |
digitalWrite(PIN_FOCUS, LOW); | |
} | |
long last; | |
void loop() { | |
if (irrecv.decode(&results)) { | |
Serial.println(results.value, HEX); | |
if(results.value == key_plus100){ | |
incShutter(100); | |
} | |
if(results.value == key_plus200){ | |
incShutter(200); | |
} | |
if(results.value == key_eq){ | |
shutterMs = 0; | |
incShutter(100); | |
} | |
if(results.value == numerals[0]){ | |
focus(500); | |
} | |
for(int i=1;i<10;i++){ | |
if(numerals[i] == results.value){ | |
Serial.println(i); | |
take(i); | |
} | |
} | |
if(results.value!=-1){ | |
last = results.value; | |
} | |
else | |
{ //repeat code | |
if(last == numerals[0]){ | |
focus(500); | |
} | |
} | |
irrecv.resume(); // Receive the next value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment