I'm trying to code a traffic light with a pedestrian button. The idea is the default on-time for the Green, Yellow, and Red LEDS is (15s, 3s, 15s). While the light is green, every 1 sec, the program will check to see if the button has been pressed and if it has, the remaining time is halved. The yellow light duration also drops from 2s to 1.5s, and red light to 5s.
The limitations are that I cannot use timers, or interrupts. I am having difficulty with how to code it so that the program checks every 1 sec for a button press and how to keep track of how much time has passed if I cannot use any timers.
I’m trying to understand the traffic light system an how it works in practice with a pedestrian button. Are the red, yellow and green lights controlling the traffic on the road?
At what point, during the shortened cycle, does the pedestrian get a chance to cross the road and how is this point made visible to that pedestrian?
I suppose, in this context, the limitations on use of timers refers to explicit use of timer libraries. That leaves only millis() for your 1 second polling of the button. You can’t use delay() here.
Apart from the non-blocking ‘timing’, this a perfect example of where to implement a ‘state machine’.
Normally, it would run the red-yellow-green cycles, but when a button is pressed, it can branch off to a pedestrian cycle.