Consider the traffic lights in See Traffic Lights. The normal sequences for traffic lights are a green light in one direction for a long period of time, typically 10 or more seconds. This is followed by a brief yellow light, typically 4 seconds. This is then followed by a similar light pattern in the other direction. It is understood that a green or yellow light in one direction implies a red light in the other direction. Pedestrian buttons are provided so that when pedestrians are present a cross walk light can be turned on and the duration of the green light increased.
Traffic Lights
The first step for developing a controller is to define the inputs and outputs of the system as shown in See Inputs and Outputs for Traffic Light Controller. First we will describe the system variables. These will vary as the system moves from state to state. Please note that some of these together can define a state (alone they are not the states). The inputs are used when defining the transitions. The outputs can be used to define the system state.
Inputs and Outputs for Traffic Light Controller
Previously state diagrams were used to define the system, it is possible to use a state table as shown in See System State Table for Traffic Lights. Here the light sequences are listed in order. Each state is given a name to ease interpretation, but the corresponding output pattern is also given. The system state is defined as the bit pattern of the 6 lights. Note that there are only 4 patterns, but 6 binary bits could give as many as 64.
System State Table for Traffic Lights
Transitions can be added to the state table to clarify the operation, as shown in See State Table with Transitions. Here the transition from Green E/W to Yellow E/W is S1. What this means is that a cross walk button must be pushed to end the green light. This is not normal, normally the lights would use a delay. The transition from Yellow E/W to Green N/S is caused by a 4 second delay (this is normal.) The next transition is also abnormal, requiring that the cross walk button be pushed to end the Green N/S state. The last state has a 4 second delay before returning to the first state in the table. In this state table the sequence will always be the same, but the times will vary for the green lights.
State Table with Transitions
A state diagram for the system is shown in See A Traffic Light State Diagram. This diagram is equivalent to the state table in See State Table with Transitions, but it can be valuable for doing visual inspection.
A Traffic Light State Diagram