// Define the LED pins and button pin
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BUTTON_PIN = 2;
void setup() {
// Set LED pins as output
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
// Set button pin as input with pull-up resistor
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
// Read button state
int buttonState = digitalRead(BUTTON_PIN);
if (buttonState == LOW) {
// Button is pressed, turn on green LED and turn off red LED
digitalWrite(GREEN_LED_PIN, LOW);
digitalWrite(RED_LED_PIN, HIGH);
} else {
// Button is not pressed, turn on red LED and turn off green LED
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, HIGH);
}
// Wait a short time to debounce the button
delay(50);
}