ok, I give.
I had excellent input from which I have learned from...but...I can't get this to do what I want. I got the code to compile and circuit seems right, but when I try and cycle through programs, it will respond to a button push, but then revert back to what it was doing.
OK vague.
Goal: push button: start first program, push button: go to 2nd program, push button: got to 3rd program, push button: stop.
NOW: I have tried tinkering with it and lowering the "cases" to understand the system.
I upload and it the LED blinks..then when I push the button it stops for a second...then starts blinking again..
Though I have had excellent input and advice, I still am at odds with this.
Is a momentary button not right for turning on a system-cycling through programs ans turning off??
int LED = 13;
int Button = 12;
int programState = 0;
void setup()
{
pinMode(LED,OUTPUT);
pinMode(Button,INPUT);
digitalWrite(Button,HIGH); //enable pull-up
}
void loop(){
if (digitalRead (Button)==0){ // assumes button declared as INPUT with internal pullup enabled
programState = programState +1;}
if (programState ==2){ // reset after 5, or whatever amount you select
programState = 1;
}
switch(programState)
{
case 1:
digitalWrite(LED,HIGH);
delay (100);
digitalWrite(LED,LOW);
delay(100);
case 2:
digitalWrite(LED,LOW); //off
}
}