const int buttonPin = 19; // Button pin
const int ledPin = 2; // LED pin
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Set the button pin as input with internal pull-up resistor
pinMode(ledPin, OUTPUT); // Set the LED pin as output
}
void loop() {
// Read the state of the button (LOW when pressed, HIGH when not pressed due to INPUT_PULLUP)
int buttonState = digitalRead(buttonPin);
// If the button is pressed, turn on the LED, else turn it off
if (buttonState == LOW) {
digitalWrite(ledPin, HIGH); // Turn the LED on
} else {
digitalWrite(ledPin, LOW); // Turn the LED off
}
}