const int buttonPin = 27; // the number of the pushbutton pin const int ledPin1 = 26; // the number of the first LED pin const int ledPin2 = 0; // the number of the second LED pin const int ledPin3 = 1; // the number of the third LED pin int buttonState = 0; // variable for reading the pushbutton status int lastButtonState = 0; // variable to store the previous state of the button unsigned long pressStartTime = 0; // variable to store the time when button was pressed unsigned long pressDuration = 0; // variable to store the duration of button press void setup() { pinMode(buttonPin, INPUT); pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); // Initialize serial communication: Serial.begin(9600); } void loop() { // read the state of the pushbutton value: int reading = digitalRead(buttonPin); // check if the button state has changed if (reading != lastButtonState) { // reset the debouncing timer pressStartTime = millis(); } // if the button is pressed if (reading == HIGH) { pressDuration = millis() - pressStartTime; if (pressDuration < 1000) { digitalWrite(ledPin1, HIGH); } else if (pressDuration >= 1000 && pressDuration < 2000) { digitalWrite(ledPin2, HIGH); } else if (pressDuration >= 2000 && pressDuration < 3000) { digitalWrite(ledPin3, HIGH); } else if (pressDuration >= 3000) { digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); } } // save the current button state for comparison in the next loop iteration lastButtonState = reading; }