I have an task for my class where we have to make 2 LEDS blink alternatively using a pushbutton. I've figured out how to do the blinking and alternating but from time to time one of the led would go twice in a row instead of the other led blinking. Need help figuring out what's making it do this in my code. I'm using Tinkercad with Arduino UNO.
int buttonPin = 7;
int redledpin = 11;
int orangeledpin = 12;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}
void loop () {
if (digitalRead(buttonPin) == HIGH) {
digitalWrite(11, LOW);
digitalWrite(12, LOW);
} else {
digitalWrite(11, HIGH);
delay(500);
digitalWrite(11, LOW);
delay(500);
}
if (digitalRead(buttonPin) == HIGH) {
digitalWrite(11, LOW);
digitalWrite(12, LOW);
} else {
digitalWrite(12, HIGH);
delay(500);
digitalWrite(12, LOW);
delay(500);
}
if (digitalRead(buttonPin) == HIGH) {
digitalWrite(11, LOW);
digitalWrite(12, LOW);
}
}
ifblock, but then you set the state of only one LED in the second part of theifblock