I would like to know if there is anything wrong in my code. My programm works but not well, for example when the state changes from buttonPin2==HIGH to buttonPin3== HIGH the led1 does not turn off inmediatly, it starts blinking for a few second and then turns off.
const int buttonPin2 = 7;
const int led1 = 1;
const int led2 = 10;
const int led3 = 9;
const int buttonPin3 = 6;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
}
void loop() {
if (digitalRead(buttonPin2) == HIGH) {
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
else if (digitalRead(buttonPin3) == HIGH ) {
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(ledPin3, LOW);
delay(1000);
digitalWrite(led2, LOW);
digitalWrite(led1, LOW);
digitalWrite(led3, HIGH);
delay(1000);
}
else{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
}