Hi!
I'm trying to make a diode blink continuously when i press the button, and the turn off when i press the same button again.
Right now the diode only blinks once and turns off.
I think i need to make my "else" statement loop until i press the button again, but i don't know how.
here is my code:
const int button = 2;
const int led = 13;
int ledState = HIGH;
int buttonCurrent;
int buttonPrevious = LOW;
void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop() {
buttonCurrent = digitalRead(button);
if (buttonCurrent == HIGH && buttonPrevious == LOW)
{
if(ledState == HIGH)
{
ledState = LOW;
digitalWrite(led, LOW);
}
else
{
ledState = HIGH;
digitalWrite(led, HIGH);
delay(400);
digitalWrite(led, LOW);
delay(400);
}
}
buttonPrevious = buttonCurrent;
}