Traffic light simulator
The Raspberry Pi (see
Raspberry Pi Description) is the embedded system we use for our course. It can connect to the outside world through different types of interfaces. The most simple one is the connection through GPIO (General Purpose I/O) pins which are logic levels that can be input or output. When these pins are programmed as outputs, then they can drive LEDs (Light Emitting Diodes) and switch them on or off. Since lighting a single LED is not exactly spectacular we prepared a simulation of traffic lights.
Imagine a road crossing where you have traffic lights on both roads. When the traffic light is green on one road it must be red on the other. The traffic lights are in this state for some time to make a good number of cars pass the crossing. Then the green light turns to yellow while the light on the other road is still red. This is a short phase just allowing the cars, which are already on the crossing to clear it. Then we keep both lights on red for a short period as a safety phase, before switching the other traffic light to green, again for a longer period.
There are therefore the following phases:
Traffic Light 1 | Traffic Light 2 | Period |
green | red | long |
yellow | red | short |
red | red | short |
red | green | long |
red | yellow | short |
red | red | short |
When running the program on the Raspberry Pi or on the Arduino, these phases can be observed. The whole program can be implement as a simple state machine.
... and here you see the traffic light simulator in action:
--
Uli Raich - 2017-10-06
Comments
Topic revision: r3 - 2017-10-11
- uli