#define pinPB 15
#define LED1 5
#define LED2 19
#define LED3 18
// Variable yang akan berubah:
//int lastState = HIGH; // kondisi PB sebelum ditekan
int currentState; // kondisi PB terkini
void setup() {
Serial.begin(115200);
pinMode(pinPB, INPUT_PULLUP);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
void loop() {
// baca kondisi PB
currentState = digitalRead(pinPB);
if (currentState == HIGH)
{
digitalWrite(LED1, HIGH);
delay(1000);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);
delay(1000);
digitalWrite(LED2, LOW);
digitalWrite(LED3, HIGH);
delay(1000);
digitalWrite(LED3, LOW);
}
else
{
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
}
// if(lastState == LOW && currentState == HIGH)
// Serial.println("kondisi berubah dari LOW jadi HIGH");
// save the last state
//lastState = currentState;
}