My teacher asked us to develop a traffic light application. The application will have three buttons:
- start: to start the traffic light. When we press the button, we see a red circle, 2 seconds after we see a green circle, 3 seconds after we see an orange circle for 0.4 seconds, and then we see a red circle, and we repeat the same again.
- stop: we see a white circle
- breakdown: in this mode, we see an orange circle for 0.5 seconds, and then a white circle for 0.6 seconds and an orange circle again.
The first question is how many timers should we use. I replied that we can only use one timer that will post events every 0.1 seconds. Teacher said that this is a bad idea, and we should use 5 timers. He said that I would have a problem if I ran many programs on my computer (overload).
Why is my decision not so good? Using a large number of timers will not complicate the decision?
Edit:
He said that we need 5 timers because there are five events (from red to green, from green to orange, from orange to red, from orange to white, from white to orange). He said that if we add more colors, we will also add timers.
Here is his logic:
timer1 has interval of 2 seconds
timer2 has interval of 3 seconds
timer3 has interval of 0.4 seconds
timer4 has interval of 0.5 seconds
timer5 has interval of 0.6 seconds
1 , , , 1 2
timer2 , . timer2, timer3.
timer3 , . timer3, timer1.
, .