const int redLedPin = 1;
const int yellowLedPin = 2;
const int greenLedPin = 3;
const int buttonPin = 7;
unsigned long previusMillis = 0;
const long redInterval = 3000;
const long yellowInterval = 2000;
const long greenInterval = 3000;
long extraRedInterval = 3000;
long currentInterval = 0;
int ledState = LOW;
int currentLed = 0;
bool extraTime;
void setup() {
// put your setup code here, to run once:
pinMode(redLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
unsigned long currentMillis = millis();
int buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
extraTime = true;
}
if(currentMillis - previusMillis >= currentInterval){
previusMillis = currentMillis;
turnOffLeds();
if(currentLed == 0){
digitalWrite(redLedPin, HIGH);
currentInterval = redInterval;
if(extraTime){
currentInterval += extraRedInterval;
extraTime = false;
}
currentLed = 1;
}
else if (currentLed == 1){
digitalWrite(yellowLedPin, HIGH);
currentInterval = yellowInterval;
currentLed = 2;
}
else if (currentLed == 2){
digitalWrite(greenLedPin, HIGH);
currentInterval = greenInterval;
currentLed = 0;
}
}
}
void turnOffLeds(){
digitalWrite(redLedPin, LOW);
digitalWrite(yellowLedPin, LOW);
digitalWrite(greenLedPin, LOW);
}