#define LED_hijau 13
#define LED_biru 12
#define LED_merah 11
#define tombol 7
int status = 0;
void setup() {
// put your setup code here, to run once:
pinMode(LED_hijau, OUTPUT);
pinMode(tombol, INPUT);
pinMode(LED_biru, OUTPUT);
pinMode(LED_merah, OUTPUT);
digitalWrite(LED_hijau, LOW);
digitalWrite(LED_biru, LOW);
digitalWrite(LED_merah, LOW);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(tombol) == HIGH) {
status++;
delay(500);
}
if (status == 1) {
digitalWrite(LED_hijau, HIGH);
} else if (status == 2) {
digitalWrite(LED_biru, HIGH);
} else if (status == 3) {
digitalWrite(LED_merah, HIGH);
} else if (status == 4) {
digitalWrite(LED_hijau, LOW);
digitalWrite(LED_biru, LOW);
digitalWrite(LED_merah, LOW);
} else if (status == 5) {
digitalWrite(LED_merah, HIGH);
digitalWrite(LED_biru, LOW);
digitalWrite(LED_hijau, LOW);
} else if (status == 6) {
digitalWrite(LED_merah, LOW);
digitalWrite(LED_biru, HIGH);
digitalWrite(LED_hijau, LOW);
} else if (status == 7) {
digitalWrite(LED_merah, LOW);
digitalWrite(LED_biru, LOW);
digitalWrite(LED_hijau, HIGH);
} else if (status == 8) {
digitalWrite(LED_hijau, LOW);
digitalWrite(LED_biru, LOW);
digitalWrite(LED_merah, LOW);
} else if (status == 9) {
Serial.println("Status 9, Lampu berkedip, Kemudian Reset");
for (int i = 0; i < 3; i++) {
digitalWrite(LED_hijau, HIGH);
digitalWrite(LED_biru, LOW);
digitalWrite(LED_merah, LOW);
delay(200);
digitalWrite(LED_hijau, LOW);
digitalWrite(LED_biru, HIGH);
digitalWrite(LED_merah, LOW);
delay(200);
digitalWrite(LED_hijau, LOW);
digitalWrite(LED_biru, LOW);
digitalWrite(LED_merah, HIGH);
delay(200);
}
status = 0; // reset ke status 0
digitalWrite(LED_hijau, LOW);
digitalWrite(LED_biru, LOW);
digitalWrite(LED_merah, LOW);
delay(200);
}
Serial.print("Status saat ini: ");
Serial.println(status);
}