#define sw1 14
#define sw2 13
#define sw3 27
#define sw4 26
#define led1 25
#define led2 33
#define led3 32
bool led1State = HIGH;
bool led2State = HIGH;
bool led3State = HIGH;
int swState;
int lastswState = HIGH;
int swState2;
int lastswState2 = HIGH;
int swState3;
int lastswState3 = HIGH;
int swState4;
int lastswState4 = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
Serial.begin(115200);
pinMode(sw1, INPUT);
pinMode(sw2, INPUT);
pinMode(sw3, INPUT);
pinMode(sw4, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
int reading = digitalRead(sw1);
if (reading != lastswState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != swState) {
swState = reading;
if (swState == LOW) {
digitalWrite(led1, HIGH);
}
}
}
lastswState = reading;
int reading2 = digitalRead(sw2);
if (reading2 != lastswState2) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading2 != swState2) {
swState2 = reading2;
if (swState2 == LOW) {
digitalWrite(led2, HIGH);
}
}
}
lastswState2 = reading2;
int reading3 = digitalRead(sw3);
if (reading3 != lastswState3) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading3 != swState3) {
swState3 = reading3;
if (swState3 == LOW) {
digitalWrite(led3, HIGH);
}
}
}
lastswState3 = reading3;
int reading4 = digitalRead(sw4);
if (reading4 != lastswState4) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading4 != swState4) {
swState4 = reading4;
if (swState4 == LOW) {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
}
}
}
lastswState4 = reading4;
}