#define BUTTON1_PIN 2 // Pin for the first button
#define BUTTON2_PIN 3 // Pin for the second button
#define LED1_PIN 13 // Pin for the first LED
#define LED2_PIN 12 // Pin for the second LED
bool led1State = false; // State of LED 1
bool led2State = false; // State of LED 2
void setup() {
Serial.begin(9600); // Start serial communication for debugging
pinMode(BUTTON1_PIN, INPUT_PULLUP); // Set button 1 pin as input with pull-up resistor
pinMode(BUTTON2_PIN, INPUT_PULLUP); // Set button 2 pin as input with pull-up resistor
pinMode(LED1_PIN, OUTPUT); // Set LED 1 pin as output
pinMode(LED2_PIN, OUTPUT); // Set LED 2 pin as output
}
void loop() {
// Read the state of Button 1
if (digitalRead(BUTTON1_PIN) == LOW) { // Button is pressed
led1State = !led1State; // Toggle LED 1 state
digitalWrite(LED1_PIN, led1State); // Update LED 1
Serial.println("Button 1 pressed, toggling LED 1");
delay(300); // Delay to avoid multiple toggles from button bounce
}
// Read the state of Button 2
if (digitalRead(BUTTON2_PIN) == LOW) { // Button is pressed
led2State = !led2State; // Toggle LED 2 state
digitalWrite(LED2_PIN, led2State); // Update LED 2
Serial.println("Button 2 pressed, toggling LED 2");
delay(300); // Delay to avoid multiple toggles from button bounce
}
// Add a small delay to avoid rapid toggling
delay(10);
}