// Define the pins for the LEDs and the button const int ledPin1 = D0; const int ledPin2 = D7; const int buttonPin = D1; // Variables to store the state of the button and LEDs int buttonState = HIGH; // current state of the button int lastButtonState = HIGH; // previous state of the button bool ledState1 = false; // current state of the first LED bool ledState2 = false; // current state of the second LED // Variable to store the last time the button was pressed unsigned long lastDebounceTime = 0; unsigned long debounceDelay = 50; // debounce time in milliseconds void setup() { // Initialize the LED pins as outputs pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); // Initialize the button pin as an input pinMode(buttonPin, INPUT_PULLUP); // Set the initial state of the LEDs digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); } void loop() { // Read the state of the button int reading = digitalRead(buttonPin); // Check if the button state has changed if (reading != lastButtonState) { // Reset the debounce timer lastDebounceTime = millis(); } // If enough time has passed, consider it a valid button press if (millis() - lastDebounceTime > debounceDelay) { // If the button state has changed, update the button state if (reading != buttonState) { buttonState = reading; // If the button is pressed, toggle the LEDs if (buttonState == LOW) { ledState1 = !ledState1; ledState2 = !ledState2; digitalWrite(ledPin1, ledState1 ? HIGH : LOW); digitalWrite(ledPin2, ledState2 ? HIGH : LOW); } } } // Save the current button state for comparison lastButtonState = reading; }