// Define GPIO pins for the three push buttons
const int buttonPin1 = 7; // Button 1 connected to GPIO 7
const int buttonPin2 = 5; // Button 2 connected to GPIO 5
const int buttonPin3 = 4; // Button 3 connected to GPIO 4
// Define GPIO pins for LED
const int ledPin = 3; // LED connected to GPIO 3
// Variable to store the state of the LED
bool ledState = false;
void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
// Initialize the button pins as inputs
pinMode(buttonPin1, INPUT_PULLUP); // Button 1 uses internal pull-up resistor
pinMode(buttonPin2, INPUT_PULLUP); // Button 2 uses internal pull-up resistor
pinMode(buttonPin3, INPUT_PULLUP); // Button 3 uses internal pull-up resistor
}
void loop() {
// Read the state of each button
bool buttonState1 = digitalRead(buttonPin1);
bool buttonState2 = digitalRead(buttonPin2);
bool buttonState3 = digitalRead(buttonPin3);
// Button 1: Turn on the LED
if (buttonState1 == LOW) {
digitalWrite(ledPin, HIGH); // Turn on the LED
}
// Button 2: Turn off the LED
if (buttonState2 == LOW) {
digitalWrite(ledPin, LOW); // Turn off the LED
}
// Button 3: Toggle the state of the LED
if (buttonState3 == LOW) {
ledState = !ledState; // Toggle the LED state
digitalWrite(ledPin, ledState); // Update the LED state
delay(10000); // Add a small delay to debounce the button
}
}