The application simulates the operation of a single traffic light consisting of three sections (green, yellow and red) in manual and automatic modes. In manual mode any section can be tuned on and off arbitrarily. In automatic mode the traffic light works according to its standard program. When the application is started, a graphic window opens (Fig. 1) in which the traffic light is programmatically drawn using the simple graphic primitives. The application is written in С using Win32API. It can successfully be compiled with the Mingw-w64 – GCC and run under Windows (7 and higher).
Fig.1. Traffic light view with all sections turned off (left) and turned on (right).
When the application is running, the traffic light can be controlled using the keyboard. Control occurs by pressing the following keys and their combinations:
Ctrl + M
Switch to the manual operation mode
Ctrl + A
Switch to the automatic operation mode
When switching to the automatic operation mode, the traffic light starts its work from the state “green light is on”. State diagram for the automatic mode is shown in Fig. 2. Duration of the states can be easily changed by modifying constants in simulation.c
file. When switching to the manual operation mode, sections preserve their states that were before the switch. In this mode, sections are switched on and off as follows:
F1
Turning green section on/off
F2
Turning yellow section on/off
F3
Turning red section on/off
Regardless of the operation mode, pressing the ESC
key terminates the application.
Fig.2. Set of possible states of the traffic light working in automation mode.
Installation, compilation and run of the application occurs when executing commands in a terminal window (The method is described for a UNIX-like terminal, for example, Bash from MSYS2. It also requires a working Mingw-w64 - GCC compiler and configured paths).
- Copying the repository to a local directory:
$ git clone https://github.com/juvus/Traffic_light_simulator.git
$ cd Traffic_light_simulator/
- Compiling of the application:
$ mingw32-make
- Running the application:
$ cd build/
$ ./Program
-
include/
Public header files -
resources/
Application resources (Accelerator table) -
src/
Source code files -
img/
Images, necessary for the documentation
Traffic light simulator code in this project is available under the GPLv3
license. You can find the license file here: LICENSE