Hello I am working on a code that lets 2 led blink without delay while at the same time allows me to press a push button to allow a 3rd to light up. The problem I am having is the code only runs the first part the 2 blink without delay but it does not run the second part which is to turn the 3rd LED on with a button. I tried to combine the blink without delay code and a push button code to see if it would work but it did not here is my code.
const int LY=9;
const int LR=10;
const int LB=12;
const int BUTTON=11;
const int fade=10;
int ButtonState =0;
int ledState = LOW;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;
boolean ledOn1 = false;
unsigned long previousMillis = 0;
const long interval = 1;
void setup() {
pinMode(LY, OUTPUT);
pinMode(LR, OUTPUT);
pinMode(BUTTON, INPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON);
if (last != current)
{
delay(5);
current = digitalRead(BUTTON);
}
}
void loop(){
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledOn1 = !ledOn1;
}
lastButton = currentButton;
digitalWrite(LB, ledOn1);
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledOn == LOW) {
ledOn = HIGH;
} else {
ledOn = LOW;
}
}
digitalWrite(LR, ledOn);
delay(100);
digitalWrite(LR, LOW);
delay(100);
digitalWrite(LY,ledOn);
delay(100);
digitalWrite(LY, LOW);
delay(100);
}
}
Any tips or advice for me?
Thank you for your time.