When I put the second IF statement in, the red light is always on.
I'm trying to make the light green if the A button is pressed and red if the D button is pressed. Here is my code. What am I doing wrong?
const int buttona= 6;
const int buttond = 4;
const int redPin= 8;
const int greenPin = 7;
int buttonStatea = 0;
int buttonStated = 0;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(buttona, INPUT);
pinMode(buttond, INPUT);
}
void loop() {
buttonStatea = digitalRead (buttona);
buttonStated = digitalRead (buttond);
if(buttonStatea == HIGH)
{
digitalWrite(greenPin, HIGH);
delay(1000);
digitalWrite (greenPin, LOW);
}
if (buttonStated == HIGH)
{
digitalWrite(redPin, HIGH);
delay(1000);
digitalWrite(redPin, LOW);
}
}
question1.ino (1.21 KB)