const int buttonPin = 14;
const int ledPin1 = 33;
const int ledPin2 = 32;
bool state1 = false;
bool state2 = false;
bool state3 = false;
unsigned long buttonStartTime = 0;
const int longPressDuration = 1000; // Set the duration for a long press in milliseconds
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop() {
int buttonState = digitalRead(buttonPin);
int value2 = digitalRead(27);
int value3 = digitalRead(26);
if (buttonState == LOW) {
if (millis() - buttonStartTime > longPressDuration) {
// Long press detected
state3 = !state3;
} else {
// Short press detected
state1 = !state1;
state3 = false; // Reset state3 on short press
}
buttonStartTime = millis(); // Reset the button start time
}
if (value2 == LOW) {
state2 = !state2;
}
digitalWrite(ledPin1, state1 || state3); // Turn on led1 if state1 or state3 is true
digitalWrite(ledPin2, state2 || state3); // Turn on led2 if state2 or state3 is true
delay(50); // Adjust the delay as needed, lower values will make the response faster
}