int buttonPin = 2; // Digital pin where the button is connected.
int BLedPin = 4;
int RLedPin = 7;
int GLedPin = 5; // Digital pin where the LED is connected.
bool buttonState = false;
void setup() {
// put your setup code here, to run once:
pinMode(BLedPin, OUTPUT); // LED pin as an output.
pinMode(buttonPin, INPUT);
pinMode(GLedPin, OUTPUT);
pinMode(RLedPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == HIGH){
digitalWrite(BLedPin, HIGH);
digitalWrite(BLedPin, LOW);
digitalWrite(GLedPin, HIGH);
digitalWrite(GLedPin, LOW); // Turn LED on.
} else {
digitalWrite(RLedPin, HIGH); // Turn LED off.
}
}