i'm trying to make a pushbutton toggle a loop on/off.
When the loop is running, some LEDs should blink in turn (in a loop) and when it's off, just one of them should emit light.
I'm at the point where i get them to blink in turn when i push the button, but they run through the sequence just once and then return to "off" (where just one of them are on).
const int redpin = 2;
const int greenpin = 3;
const int yellowpin = 4;
const int bluepin = 5;
const int buttonPin = 6;
int buttonState = 0;
I'm at the point where i get them to blink in turn when i push the button, but they run through the sequence just once and then return to "off" (where just one of them are on).
Which one is on?
If you release the switch, the state changes to LOW (if you have the switch wired properly). If you want the blinking to continue, you need to look at the state change detection example, and determine when the switch becomes pressed once, twice, three times, etc.
Each time, you toggle the value of a flag (blinking, not blinking, blinking, etc.).
Independently, you blink the LED if blinking is true, or light the one LED if blinking is false.