const int pinMerah = 2;
const int pinKuning = 3;

unsigned long mulaiMerah = 0;
unsigned long mulaiKuning = 0;
const unsigned long intervalMerah = 3000;
const unsigned long intervalKuningOn = 5000;
const unsigned long intervalKuningOff = 8000;

void setup() {
  pinMode(pinMerah, OUTPUT);
  pinMode(pinKuning, OUTPUT);
}

void loop() {
  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;
    }
  }
}