// Pin definitions const int buttonPin = 27; // The pin where the button is connected const int ledPin = 1; // The pin where the LED is connected // Variables unsigned long buttonPressedTime = 0; // Variable to store the time the button was pressed bool ledState = false; // Variable to store the LED state void setup() { pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output pinMode(buttonPin, INPUT_PULLUP); // Initialize the button pin as an input with internal pull-up resistor } void loop() { // Read the state of the button int buttonState = digitalRead(buttonPin); // Check if the button is pressed if (buttonState == LOW) { // If the button is pressed, record the time it was pressed buttonPressedTime = millis(); ledState = !ledState; // Toggle LED state } // If the LED is on, check if it's time to turn it off if (ledState && (millis() - buttonPressedTime >= 1000)) { digitalWrite(ledPin, LOW); // Turn off the LED ledState = false; // Update LED state } // If the LED is off, check if it's time to turn it on if (!ledState && (buttonState == HIGH)) { digitalWrite(ledPin, HIGH); // Turn on the LED buttonPressedTime = millis(); // Record the time LED was turned on ledState = true; // Update LED state } }