The following sketch works well with one exception. The LED only flashes when momentary push button is held down. I need it to flash until I press another button. How do I make this momentary PB (const int pin_lightOn = 43;)act like a toggle switch?
Thanks for the help
const int pin_lightOn = 43;//button to turn on light
const byte lightLed = 36; //light on led
bool blinking = false; //defines when blinking should occur
unsigned long blinkInterval = 250; // number of milliseconds for blink
unsigned long currentMillis; // variables to track millis()
unsigned long previousMillis;
void setup() {
pinMode (pin_lightOn, INPUT_PULLUP);
pinMode (lightLed, OUTPUT);
}
void loop() {
// this code blinks the LED
if (blinking) {
currentMillis = millis(); // better to store in variable, for less jitter
if ((unsigned long)(currentMillis - previousMillis) >= blinkInterval) { // enough time passed yet?
digitalWrite(lightLed, !digitalRead(lightLed)); // shortcut to toggle the LED
previousMillis = currentMillis; // sets the time we wait "from"
}
} else {
digitalWrite(lightLed, LOW); // force LED off when not blinking
}
int reading = digitalRead(pin_lightOn);
delay(50); // crude de-bouncing
if (reading== LOW) // buttons with pull-up are pressed when LOW
blinking=true; // start blinking
else
blinking=false; // stop blinking
}