const int buttonPin = 14; // the number of the pushbutton pin
const int ledPin = 23; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
unsigned long previousMillis = 0; // stores the time of the last button press
unsigned long currentMillis = 0; // stores the time of the current button press
const unsigned long interval = 5000; // minimum interval in milliseconds
void setup() {
pinMode(ledPin, OUTPUT); // initialize LED pin as an output
pinMode(buttonPin, INPUT_PULLDOWN); // initialize pushbutton pin as an input
}
void loop() {
buttonState = digitalRead(buttonPin); // read the state of the pushbutton
if (buttonState == HIGH) { // if button is pressed
currentMillis = millis(); // record the current time
if (currentMillis - previousMillis >= interval) {
digitalWrite(ledPin, HIGH); // turn on LED if interval is greater than 5 seconds
delay(500);
}
previousMillis = currentMillis; // update previous time to current time
} else {
digitalWrite(ledPin, LOW); // turn off LED if button is not pressed
}
}