Hi all, I am just writing some code for a simple time lapse controller that I've built.
I am trying to integrate a button, and once it is pressed (to gnd) I want to go into a while loop with a counter built in.
The code compiles and is running, but its running through the if and for loops constantly, irrespective of the button state?
What am I doing wrong guys?
Thanks
#include <LiquidCrystal.h>
//Pin naming
int focusPin = 2;
//int focusLED = 13;
int shutterPin = 4;
int shutterLED = 13;
int enterButton = A2;
int pauseButton = A1;
int LDRPin = A5; // Analog input pin that the lDR is attached to
int LCDBackLight = 3; // Analog (PWM) output pin that the BACKLIGHT is attached to
int amountPot = A4;
int intervalPot = A3;
//Parameters
int focusDelay = 800;
int shutterDelay = 800;
//int interval = 20000;
int maxInterval = 600000; //Max interval between shots in millis allowed
int maxAmount = 1000; //Maxium amount of shots allowed
const int minLight = 40; // at or below this light level, use minimum backlight intensity
const int maxLight = 900; // at or above this light level, use maximum backlight intensity
const int minBacklight = 20; // lowest backlight intensity to use
const int maxBacklight = 255; // highest backlight intensity to use
int LDRRead = 0; // value read from the LDR
int outputValue = 0; // value output to the PWM (analog out)
int intervalRead = 0; // value read from the interval pot
int amountRead = 0; // value read from amount of photos pot
int interval = 0;
int amount = 0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
//Set up LCD
lcd.begin(16, 2);
delay(100);
//Set up pins
pinMode(focusPin, OUTPUT);
pinMode(shutterPin, OUTPUT);
pinMode(shutterLED, OUTPUT);
pinMode(LCDBackLight, OUTPUT);
pinMode(enterButton, INPUT);
pinMode(pauseButton, INPUT);
//enable pull ups on buttons
digitalWrite(enterButton, HIGH);
digitalWrite(pauseButton, HIGH);
}
void loop(){
int shots = 0;
// LDR controlled LCD backlight via PWM part
int sum = 0;
for (int i=0; i<16; i++) // take 16 samples from the analog input
{
sum += analogRead(LDRPin);
}
LDRRead = sum/16; // divide by the amount of samples for the average value
// map it to the range[0..255] of the analog output that the LCD backlight it connected to
outputValue = LDRRead/4; // alternative to map function for scaling down from analog input
outputValue = map(constrain(LDRRead, minLight, maxLight), minLight, maxLight, minBacklight, maxBacklight );
// change the analog out value to adjust LCD backlight intensity
analogWrite(LCDBackLight, outputValue);
// read interval from pot
intervalRead = analogRead(intervalPot);
interval = map (interval, 0, 1023, 0, maxInterval);
// read amount from pot
// amountRead = analogRead(amountPot);
//amount = map (amount, 0, 1023, 0, maxAmount);
amount = 10;
lcd.setCursor(0,0);
lcd.print("Shots:");
lcd.print(amount );
lcd.setCursor(0,1);
lcd.print("Delay:");
lcd.print(interval );
digitalRead(enterButton);
if (enterButton == LOW);
{
while (shots < amount)
{
lcd.setCursor(0,0);
lcd.print("Shots:");
lcd.print(amount);
lcd.print("/");
lcd.print(shots + 1 );
//Trigger focus
digitalWrite(focusPin, HIGH);
delay(focusDelay);
//Trigger shutter
digitalWrite(shutterPin, HIGH);
digitalWrite(shutterLED, HIGH);
delay(shutterDelay);
digitalWrite(shutterPin, LOW);
digitalWrite(shutterLED, LOW);
digitalWrite(focusPin, LOW);
delay(interval);
shots++;
}
}
if (enterButton == HIGH);
{
//do nothing
}
}