void loop()
{
if ( digitalRead(firstButton) == HIGH )
{
digitalWrite(greenLed, HIGH);
delay(ledDelay);
digitalWrite(greenLed, LOW);
}
else if ( digitalRead(secondButton) == HIGH )
{
digitalWrite(blueLed, HIGH);
delay(ledDelay);
digitalWrite(blueLed, LOW);
}
else if ( digitalRead(thirdButton) == HIGH )
{
digitalWrite(redLed, HIGH);
delay(ledDelay);
digitalWrite(redLed, LOW);
}
}
so my question is that when my code executes and runs on Arduino and when I press my firstbutton and leave it to make my IF statements condition TRUE and after the condition is TRUE. it first turns ON the green led and after that 2-SEC DELAY it turns OFF the led but instead of leaving the button if I hold it then it must turn ON the led and then after a 2-sec delay it will turn OFF and these will repeat again and again but instead of this led remains ON as long as I keep pressing the button. SO WHY IT'S NOT BLINKING?
WHY IT IS NOT READING NEXT TWO LINES AFTER digitalWrite(greenLed, HIGH); AND SKIPPING TO IF STATEMENT?
Use CTRL T to format your code then copy it and paste it here between code tags, i.e. between 2 sets of 3 grave accents ```
``` Your code is pasted here ```
Think about it...if you hold the button down then right after the LED is turned off loop() is called again and it is turned right back on so fast you can't see it turning off.
I think you need to add a second delay() after the led turns off.
In your code the led actually turns off, but when the loop repeats itself, the led turns instantly on.
You want it to blink whenever you press any button, right?
Take a look at this (and compare it with your code):