// Define pin numbers
const int ledPin = 16; // Pin connected to the LED
const int buttonPin = 17; // Pin connected to the pushbutton
// Variables for button state
int buttonState = 0;
void setup() {
// Initialize LED pin as an output
pinMode(ledPin, OUTPUT);
// Initialize button pin as an input with an internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Read the state of the pushbutton
buttonState = digitalRead(buttonPin);
// Check if the button is pressed
if (buttonState == LOW) { // Assuming button is connected to GND
// Turn the LED on
digitalWrite(ledPin, HIGH);
} else {
// Turn the LED off
digitalWrite(ledPin, LOW);
}
}