void setup() {
pinMode(2, OUTPUT); // Set GPIO2 as output for the LED.
pinMode(4, INPUT_PULLUP); // Set GPIO4 as input for the button with pull-up resistor.
}
void loop() {
int buttonState = digitalRead(4); // Read the button state.
if (buttonState == LOW) { // If button is pressed (LOW)
digitalWrite(2, HIGH); // Turn LED on.
} else {
digitalWrite(2, LOW); // Turn LED off.
}
}