void loop(){
if (digitalRead (button == LOW){ // assumes you have pin declared as INPUT with internal pullup enabled
LEDstate= LEDstate +1; // cycle thru the LED modes
if (LEDstate == 5){ // reset it last LED
LEDstate = 1;
delay (50); // debounce delay, crude
}
}
switch(LEDstate){
case 1:
digitalWrite (LED1, HIGH); // assumes HIGH output to LED Anode, cathode to resistor to ground
digitalWrite (LED5, LOW); // assume you also set all outputs LOW during void setup
break;
case 2:
digitalWrite (LED2, HIGH);
digitalWrite (LED1, LOW);
break;
case 3:
digitalWrite (LED3, HIGH);
digitalWrite (LED2, LOW);
break;
case 4:
digitalWrite (LED4, HIGH);
digitalWrite (LED3, LOW);
break;
case 5:
digitalWrite (LED5, HIGH);
digitalWrite (LED4, LOW);
break;
}
}
Well, the code would just need a minor tweak then to do what you want. How about this:
boolean pressed = false;
void loop()
{
if (digitalRead (button) == LOW){ // assumes you have pin declared as INPUT with internal pullup enabled
if (!pressed) {
LEDstate= LEDstate +1; // cycle thru the LED modes
if (LEDstate == 5){ // reset it last LED
LEDstate = 1;
}
delay (50); // debounce delay, crude
pressed = true;
}
}
else
pressed = false;
switch(LEDstate){
case 1:
digitalWrite (LED1, HIGH); // assumes HIGH output to LED Anode, cathode to resistor to ground
digitalWrite (LED5, LOW); // assume you also set all outputs LOW during void setup
break;
case 2:
digitalWrite (LED2, HIGH);
digitalWrite (LED1, LOW);
break;
case 3:
digitalWrite (LED3, HIGH);
digitalWrite (LED2, LOW);
break;
case 4:
digitalWrite (LED4, HIGH);
digitalWrite (LED3, LOW);
break;
case 5:
digitalWrite (LED5, HIGH);
digitalWrite (LED4, LOW);
break;
}
}
Hope this helps,
Brad.
PS I assume that that delay(50) should always be called? There may have been a slight error in the original code (it only did delay when LEDstate hit 5)