//Salman Taş 20191701044
#define led 12
#define pb1 2
#define pb2 3
unsigned long int button1PressTime = 0; // store button1 press time
unsigned long int button1ReleaseTime = 0; // store button1 release time
unsigned long int button2PressTime = 0; // store button2 press time
unsigned long int button2ReleaseTime = 0; // store button2 release time
void setup() {
pinMode(led, OUTPUT);
pinMode(pb1, INPUT);
pinMode(pb2, INPUT);
}
void loop() {
// Check if pb1 is pressed
if (digitalRead(pb1) == HIGH) {
if (button1PressTime == 0) {
button1PressTime = millis(); // Record the time when the button was first pressed
}
} else {
if (button1PressTime != 0) {
button1ReleaseTime = millis(); // Record the time when the button was released
unsigned long int button1Duration = button1ReleaseTime - button1PressTime; // Calculate the duration of button press
if (button1Duration >= 3000) {
digitalWrite(led, HIGH); // Turn on the LED
}
button1PressTime = 0; // Reset the button press time
}
}
// Check if pb2 is pressed
if (digitalRead(pb2) == HIGH) {
if (button2PressTime == 0) {
button2PressTime = millis(); // Record the time when the button was first pressed
}
} else {
if (button2PressTime != 0) {
button2ReleaseTime = millis(); // Record the time when the button was released
unsigned long int button2Duration = button2ReleaseTime - button2PressTime; // Calculate the duration of button press
if (button2Duration >= 3000) {
digitalWrite(led, LOW); // Turn off the LED for pb1
}
button2PressTime = 0; // Reset the button press time
}
}
}
// you need to rerelease the button after 3 second to light up the led