const int pinLED1 = 8;
const int pinLED2 = 9;
const int pinLED3 = 10;
const int pinLED4 = 11;
void setup() {
// pin LED sebagai output
pinMode(pinLED1, OUTPUT);
pinMode(pinLED2, OUTPUT);
pinMode(pinLED3, OUTPUT);
pinMode(pinLED4, OUTPUT);
}
void loop() {
// perulangan sebanyak 5 kali
// dari i=0 hinga i=4 atau (i < 5)
for(int i=0; i<5; i++){
if(i==1){
// jika i=1, hidupkan led 1, led yang lain mati
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, LOW);
digitalWrite(pinLED3, LOW);
digitalWrite(pinLED4, LOW);
}else if(i==2){
// jika i=2, hidupkan led 1 & 2, led 3 & 4 mati
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, LOW);
digitalWrite(pinLED4, LOW);
}else if(i==3){
// jika i=3, hidupkan led 1, 2, & 3, led 4 mati
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, LOW);
}else if(i==4){
// jika i=4, hidupkan semua led
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
}else{
// jika tidak, matikan semua led
digitalWrite(pinLED1, LOW);
digitalWrite(pinLED2, LOW);
digitalWrite(pinLED3, LOW);
digitalWrite(pinLED4, LOW);
}
// delai selama 5 detik
delay(2000);
}
}