// Definisi pin
const int tombol1 = 2;
const int tombol2 = 3;
const int led1 = 4;
const int led2 = 5;
const int led3 = 6;
const int led4 = 7;
void setup() {
// Konfigurasi pin tombol sebagai input
pinMode(tombol1, INPUT);
pinMode(tombol2, INPUT);
// Konfigurasi pin LED sebagai output
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() {
// Membaca status tombol
bool statusTombol1 = digitalRead(tombol1);
bool statusTombol2 = digitalRead(tombol2);
if (statusTombol1 && statusTombol2) {
// Kasus: Tombol 1 dan Tombol 2 ditekan bersamaan
// Mode running LED (1 detik)
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
delay(1000);
} else if (statusTombol1) {
// Kasus: Tombol 1 saja yang ditekan
// Flip-flop LED 1,2 dengan LED 3,4 (1 detik)
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
delay(1000);
} else if (statusTombol2) {
// Kasus: Tombol 2 saja yang ditekan
// Flip-flop LED 1,4 dengan LED 2,3 (0,5 detik)
digitalWrite(led1, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(500);
digitalWrite(led1, LOW);
digitalWrite(led4, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
delay(500);
} else {
// Kasus: Tidak ada tombol yang ditekan
// Semua LED menyala
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
}
}