const int BUTTON_PIN = 11;
const int LED_PIN = 12;
int ledState = LOW;
int buttonState;
int lastButtonState = LOW;
void setup() {
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
buttonState = digitalRead(BUTTON_PIN);
// Check if the button is pressed (HIGH)
// and check if it was unpressed (LOW)
if (buttonState == HIGH && lastButtonState == LOW) {
// Toggle the LED state
ledState = !ledState;
// Apply the new state to the LED
digitalWrite(LED_PIN, ledState);
delay(50);
}
// Save the current state for the next loop
lastButtonState = buttonState;
}