hello,
i am having a very hard time wrapping my brain around how to program this logic...
A user would press one button (I have some SPST buttons from radio shack) that would send a signal to an arduino to trigger some relays that would press buttons on a digital photo frame that would start a video, play the video, and turn off the frame when it's done, waiting for another state change to start the video back up again.
The buttons I have are either HIGH or LOW. I need to use them in the analog inputs because i'm using all the digital ones. When I have the button in analog I get a reading of 0 when it's LOW and something 20-200 when it's HIGH.
So every time I press the button, I want something to happen, and then stop and wait. Instead, when I press the button once, I get a loop, where Serial.println keeps repeating the test text I have...when I press the button again, nothing happens...
I set a boolean switch but the if conditional keeps looping. When the button state changes, it stops, but when it changes again it starts looping and doesn't stop.
I also am stumped as to how to make it so that if someone presses the button during the video play that the video won't start to play again right after...
Here is the test program I have so far:
//button is either greater than 20 or less than 20
//the button state changes between those numbers
//turn the photo frame on, run the vid,
//while running vid make sure other button presses aren't registered
//turn it off and do nothing while waiting for another change
int buttonState;
int buttonValue;
int oldButtonState;
boolean prevent;
void setup() {
Serial.begin(9600);
}
void loop() {
buttonValue = analogRead(0); //read it and see it the button is below 20 or above
//normalize the readings because it gives random numbers (but they're all above 20 if it's HIGH)
if (buttonValue > 20) {
buttonState = 30; //HIGH
}
if (buttonValue < 20) {
buttonState = 0; //LOW
}
//check to see if it changed
//if there's no change, don't do anything
//if it changed, turn on vid, turn off and wait
//this isn't working...it keeps looping. I don't understand why if the "prevent" boolean is set to true in the conditional.
if((oldButtonState != buttonState)&&(prevent==false)) {
Serial.println("Turn on lcd");
delay(200);
Serial.println("Play video");
prevent = true;
delay(2000);
Serial.println("Turn off lcd");
delay(200);
Serial.println("Wait for another change");
delay(200);
}
if (oldButtonState == buttonState){
prevent = false;
}
oldButtonState = buttonState;
}