const int pinMerah = 2;
const int pinKuning = 3;
unsigned long mulaiMerah = 0;
unsigned long mulaiKuning = 0;
const unsigned long intervalMerah = 5000;
const unsigned long intervalKuningOn = 5000;
const unsigned long intervalKuningOff = 10000;
void setup() {
// put your setup code here, to run once:
pinMode(pinMerah, OUTPUT);
pinMode(pinKuning, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long milisSekarang = millis();
if (milisSekarang - mulaiMerah >= intervalMerah){
digitalWrite(pinMerah, !digitalRead(pinMerah));
mulaiMerah = milisSekarang;
}
if (milisSekarang - mulaiKuning >= intervalKuningOn) {
if (digitalRead(pinKuning) == HIGH) {
digitalWrite(pinKuning, LOW);
mulaiKuning = milisSekarang;
} else if (milisSekarang - mulaiKuning >= intervalKuningOff) {
digitalWrite(pinKuning, HIGH);
mulaiKuning = milisSekarang;
}
}
}