Greetings all.
I'm having a small problem, I think I know what the issue is but not sure how to fix it. I'm basically trying a menu type thing. Using 1 button it should go like this:
sequence0 (default)
press button
sequence1
press button again
sequence2
press button again
sequence3
press button again
back to sequence0 //here lies the problem
Here's the main code bit;
void loop(){
state = (digitalRead(button)); //state is value of button
delay(200); //debounce(will be debounced in hardware later)
if(state==1){ //if button is pressed
newstate++; //add 1 to newstate
}
/*if(newstate==0){ //if newstate is 0 (default)
sequence0(); //run sequence0
}
if(newstate==1){ //if newstate is 1
sequence1(); //run sequence1
}
if(newstate==2){ //if newstate is 2
sequence2(); //run sequence2
}
if(newstate==3){ //if newstate is 3
sequence3(); //run sequence3
}
if(newstate>3){ //if newstate is higher than 3
newstate==0; //newstate is now 0 again, ie sequence 0
}
*/
//TRYING WITH SWITCH CASE
switch (newstate) {
case 0:
sequence0();
break;
case 1:
sequence1();
break;
case 2:
sequence2();
break;
case 3:
sequence3();
break;
default:
sequence0();
//newstate==0;
}
}
Note that i've tried it both using IF statements and trying again with switch case statements. The problem is at the same bit, getting the menu back to sequence0. I'm sure it's to do with newstate incrementing and i've tried while newstate is <3 etc but i'm obviously misplacing a line or something.
Any ideas folks?