#include <Arduino.h>
// Define button pins
#define RED_BUTTON_PIN 12
#define GREEN_BUTTON_PIN 14
// Define LED pins
#define RED_LED_PIN 27
#define GREEN_LED_PIN 26
// Define button objects
const int redButtonPin = RED_BUTTON_PIN;
const int greenButtonPin = GREEN_BUTTON_PIN;
// Define LED objects
const int redLedPin = RED_LED_PIN;
const int greenLedPin = GREEN_LED_PIN;
void setup() {
Serial.begin(115200);
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(redButtonPin, INPUT_PULLUP);
pinMode(greenButtonPin, INPUT_PULLUP);
}
void loop() {
// Check if red button is pressed
if (digitalRead(redButtonPin) == LOW) {
digitalWrite(redLedPin, HIGH); // Turn on red LED
digitalWrite(greenLedPin, LOW); // Turn off green LED
delay(500); // Wait for stability
}
// Check if green button is pressed
if (digitalRead(greenButtonPin) == LOW) {
digitalWrite(redLedPin, LOW); // Turn off red LED
digitalWrite(greenLedPin, HIGH); // Turn on green LED
delay(500); // Wait for stability
}
// If no button is pressed, turn off both LEDs
digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, LOW);
delay(100); // Small delay for stability
}