// Pin definitions
const int buttonPin = 2; // Button connected to digital pin 2
const int ledPin = 13; // LED connected to digital pin 13
// Variable to store the button state
int buttonState = 0;
void setup() {
pinMode(buttonPin, INPUT); // Set the button pin as input
pinMode(ledPin, OUTPUT); // Set the LED pin as output
}
void loop() {
// Read the state of the button
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == HIGH) {
// Turn on the LED
digitalWrite(ledPin, HIGH);
} else {
// Turn off the LED
digitalWrite(ledPin, LOW);
}
}