I'm working on a project which involves a two momentary switches and two (or more) LEDs.
I'm trying to use the momentary switches as toggle switches, to make the respective LEDs blink in .5 second intervals or to turn them off.
The momentary switch toggle issue is pretty well solved, but it's a little buggy.
My main issue is with making the LEDs blink. I can turn them steady on and off just fine, but I can't make them blink.
Here are a few snippets of code:
The toggle:
if(digitalRead(rightButton) == HIGH){
// Compare value read at RTS button to previously stored value and check if RTS is off
if(rightOn == false){ // If boolean variable "rightOn" is FALSE...
blinkRightLed();
digitalWrite(leftLed, LOW); // ...Turn left LED off
}
else{
// If boolean variable "rightOn" is TRUE...
digitalWrite(rightLed, LOW); // ...Turn right LED off
}
rightOn = !rightOn; // Switch state of boolean variable "rightOn" for next loop
}
The blink:
void blinkRightLed(){
totalTime = millis();
if(totalTime - lastTime > interval){
digitalWrite(rightLed, HIGH);
}
else{
digitalWrite(rightLed, LOW);
}
lastTime = totalTime;
}
Thanks for the help!