#define BUTTON_PIN 12
#define LED_PIN 13
bool ledState = false;
bool lastButtonState = LOW;
bool currentButtonState;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP); // Use INPUT_PULLUP for ESP32
pinMode(LED_PIN, OUTPUT);
}
void loop() {
currentButtonState = digitalRead(BUTTON_PIN);
if (currentButtonState == LOW && lastButtonState == HIGH) { // Detect button press
ledState = !ledState;
digitalWrite(LED_PIN, ledState ? HIGH : LOW);
delay(50); // Debounce delay
}
lastButtonState = currentButtonState;
}