// Pin connected to the LED
int ledPin = 13;
// Pin connected to the push button
int buttonPin = 2;
// Variable to store the button state
int buttonState = 0;
void setup() {
// Initialize the digital pin for the LED as an output
pinMode(ledPin, OUTPUT);
// Initialize the digital pin for the button as an input
pinMode(buttonPin, INPUT);
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// If the button is pressed (LOW state), turn on the LED
if (buttonState == LOW) {
digitalWrite(ledPin, HIGH);
} else { // If the button is not pressed (HIGH state), turn off the LED
digitalWrite(ledPin, LOW);
}
}