Here’s the functional code. Haven’t been able to do a test shoot yet, working some overtime lately. Thinking about testing with a light bulb or a glass of water dropping to the floor. Cheers!
#include <LiquidCrystal.h>
#include <Keypad.h>
// Setup LCD pins
LiquidCrystal lcd(22,24,26,30,32,34,36,38,40,42,44);
// Setup keypad information and pins
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {53,51,49,47};
byte colPins[COLS] = {43,41,39};
Keypad kpd = Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS);
// Setup camera pins
int focusPin = 52;
int shutterPin = 50;
// Setup sensor pins
int infraredPin = 0;
// Set program mode for dealing with user input
// 0 - idle
// 1 - millisecond input
// 2 - microsecond input
// 3 - infrared threshold input
// 4 - armed
// Initial program mode is idle
int programMode = 0;
// Default setup if none is selected by the user
unsigned int millisecondDelay = 250;
unsigned int microsecondDelay = 25000;
int infraredThreshold = 512;
// Setup initial infrared sensor value
int infraredReading = 1;
void setup()
{
// Set modes for camera pins
pinMode(focusPin,OUTPUT);
pinMode(shutterPin,OUTPUT);
// Display startup message
lcd.begin(20,4);
lcd.print(" Arduino High Speed");
lcd.setCursor(0,1);
lcd.print("Shutter Release v1.0");
lcd.setCursor(0,2);
lcd.print(" # TO ENTER SETUP");
lcd.setCursor(0,3);
lcd.print(" * TO ARM");
}
void loop()
{
// Get current infrared sensor value
infraredReading = analogRead(infraredPin);
// Check for armed mode and trigger if beam is cut
if(programMode == 4 && infraredReading < infraredThreshold)
{
delay(millisecondDelay);
delayMicroseconds(microsecondDelay);
digitalWrite(shutterPin,HIGH);
delay(5);
digitalWrite(shutterPin,LOW);
digitalWrite(focusPin,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SHUTTER RELEASED:");
lcd.setCursor(0,1);
lcd.print("Dont forget to arm");
lcd.setCursor(0,2);
lcd.print("again for the next!");
programMode = 0;
}
// Get key from keypad and respond accordingly
if(programMode != 4){
char key = kpd.getKey();
if(key)
{
switch(key)
{
case '*':
// Arm if program mode is idle
switch(programMode)
{
case 0:
programMode = 4;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("ARMED:");
lcd.setCursor(0,1);
lcd.print("Photo will be taken");
lcd.setCursor(0,2);
lcd.print("when IR beam is cut!");
digitalWrite(focusPin,HIGH);
break;
case 1:
millisecondDelay = 0;
lcd.setCursor(0,3);
lcd.print("0 ");
break;
case 2:
microsecondDelay = 0;
lcd.setCursor(0,3);
lcd.print("0 ");
break;
case 3:
infraredThreshold = 0;
lcd.setCursor(0,3);
lcd.print("0 ");
break;
}
break;
case '#':
switch(programMode)
{
case 0:
programMode = 1;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SETUP:");
lcd.setCursor(0,1);
lcd.print("Set ms + #");
lcd.setCursor(0,2);
lcd.print("No MIN or MAX for ms");
lcd.setCursor(0,3);
lcd.print(millisecondDelay);
break;
case 1:
programMode = 2;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SETUP:");
lcd.setCursor(0,1);
lcd.print("Set us + #");
lcd.setCursor(0,2);
lcd.print("Attn MIN:3 MAX:16383");
lcd.setCursor(0,3);
lcd.print(microsecondDelay);
break;
case 2:
programMode = 3;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SETUP:");
lcd.setCursor(0,1);
lcd.print("Set IR threshold + #");
lcd.setCursor(0,2);
lcd.print("Attn MIN:0 MAX:1024");
lcd.setCursor(0,3);
lcd.print(infraredThreshold);
break;
case 3:
programMode = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("IDLE: press * to arm");
lcd.setCursor(0,1);
lcd.print("ms delay = ");
lcd.print(millisecondDelay);
lcd.setCursor(0,2);
lcd.print("us delay = ");
lcd.print(microsecondDelay);
lcd.setCursor(0,3);
lcd.print("IR threshold = ");
lcd.print(infraredThreshold);
break;
}
break;
default:
switch(programMode)
{
case 1:
millisecondDelay = millisecondDelay * 10 + int(key-48);
lcd.setCursor(0,3);
lcd.print(millisecondDelay);
break;
case 2:
microsecondDelay = microsecondDelay * 10 + int(key-48);
lcd.setCursor(0,3);
lcd.print(microsecondDelay);
break;
case 3:
infraredThreshold = infraredThreshold * 10 + int(key-48);
lcd.setCursor(0,3);
lcd.print(infraredThreshold);
break;
}
break;
}
}
}
}