const int S1 = 11;
const int S2 = 10;
const int D1 = 7;
const int D2 = 6;
bool statusS2 = false; // status LED D2 (toggle)
bool lastS2 = HIGH; // status terakhir tombol S2
void setup() {
pinMode(S1, INPUT_PULLUP);
pinMode(S2, INPUT_PULLUP);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
}
void loop() {
// S1 dikendalikan langsung (on saat ditekan)
if (digitalRead(S1) == LOW) {
digitalWrite(D1, HIGH);
} else {
digitalWrite(D1, LOW);
}
// S2 dikendalikan secara toggle
bool currentS2 = digitalRead(S2);
if (lastS2 == HIGH && currentS2 == LOW) { // Deteksi jatuh (falling edge)
statusS2 = !statusS2; // toggle status
digitalWrite(D2, statusS2 ? HIGH : LOW);
}
lastS2 = currentS2;
}