This is a shorten version of the code. The print line only for help. The problem is it doesn't continue with the subroutine, but wait for the push button, because of the break command. I don't know ho to fix this.
/*Push BUTTON to switch through Modes */
boolean boItWasOn;
boolean boItIsOn;
#define ledPin0 13
#define ledPin1 12
#define LASER_THRESHHOLD 400
#define CAMERA_SHUTTER_PIN 3
#define LASER_PIN 5
#define LASER_TRIGGER_ANALOG_PIN 0
#define Sw0 8 /* Configure the program to look at digital Sw0 */
int potPin = 1; // select the input pin for the potentiometer
int valA = 0; // variable to store the value coming from the IR sensor
byte bCount=1;
void setup()
{
/Start, second block of things for tkbOutput/
pinMode(ledPin0, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(CAMERA_SHUTTER_PIN, OUTPUT); //declare the SHUTTER as Output
digitalWrite(CAMERA_SHUTTER_PIN, LOW); //Set SHUTTER pin LOW
pinMode(LASER_PIN, OUTPUT); //declare LASER pin as a Output
digitalWrite(LASER_PIN, HIGH); // Turn on the Laser
//Establish initial LED states... all off....
writeLEDs(0,0);
// Next set the state of boItWasOn according to the state of things at the outset....
boItWasOn=boSw0();
Serial.begin(9600); // open serial
}
void loop()
{
waitForChange();//Watches Sw0; changes boItWasOn and boItIsOn
delay(300); //debounce
waitForChange(); //Watches Sw0; changes boItWasOn and boItIsOn
writeNumber(bCount);
delay(300); //debounce
bCount++; //add 1
if (bCount==4){bCount=0;}; //switch back to 0 at number of counts
}
boolean boSw0()
{
return digitalRead(Sw0);
}
void writeLEDs(byte b1, byte b0)
{
digitalWrite(ledPin1,b1);
digitalWrite(ledPin0,b0);
}
void waitForChange()
{
do {
boItIsOn=boSw0();
}
while (not(boItWasOn xor boItIsOn));
boItWasOn=boItIsOn;
}
void writeNumber(byte bToWrite)
{
switch (bToWrite)
{
case 0:{writeLEDs(0,0); Serial.println("Sound Mode");break;} // Sound
case 1:{writeLEDs(0,1); Serial.println("IR Mode");break;} // Infrared detector
case 2:{writeLEDs(1,0); Serial.println("IR Mode (Break the beam to trigger shutter)");IRMODE();break;}//
I.R.
case 3:{writeLEDs(1,1); Serial.println("Lightning Mode");break;} // Lightning
}
}
void IRMODE() //Subroutine for case 2, each case will have its own subroutine
{
valA = analogRead(potPin); // read the value from the pot
int laserVal;
laserVal = analogRead(LASER_TRIGGER_ANALOG_PIN);
if (laserVal > LASER_THRESHHOLD)
{
digitalWrite(LASER_PIN, LOW); // Turn off the Laser
delay(valA); //delay acording to POT adjusment
digitalWrite(CAMERA_SHUTTER_PIN, HIGH);
Serial.println("SHUTTTER");
digitalWrite(LASER_PIN, HIGH); // Turn on the Laser
delay(500); // Keep it on for aligning of the Laser
Serial.println(laserVal, DEC);
}
}