Traffic Light 2-Way
medium
Cycles a two-direction intersection with an all-red safety phase before traffic changes direction.
What it teaches
Keeps Traffic Light Simple’s Enable control, then adds coordination between two directions. The new lesson is the all-red interlock: both directions must close before the other opens.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Enable | Input | BOOL | 0 | 1 runs the cycle; 0 resets it and shows red in both directions |
| Cfg_GreenTime | Input | DINT | 3000 | Duration of each green phase in milliseconds |
| Cfg_AmberTime | Input | DINT | 1500 | Duration of each amber phase in milliseconds |
| Cfg_AllRedTime | Input | DINT | 2000 | Duration of each all-red safety phase in milliseconds |
| Out_NSGreen | Output | BOOL | 0 | North-south green light |
| Out_NSAmber | Output | BOOL | 0 | North-south amber light |
| Out_NSRed | Output | BOOL | 0 | North-south red light |
| Out_EWGreen | Output | BOOL | 0 | East-west green light |
| Out_EWAmber | Output | BOOL | 0 | East-west amber light |
| Out_EWRed | Output | BOOL | 0 | East-west red light |
Required behavior
- When In_Enable is 0, both directions show red and the sequence resets to its starting phase.
- When In_Enable changes to 1, the cycle starts with north-south green and east-west red.
- The six phases repeat in order: NS green, NS amber, all red, EW green, EW amber, all red.
- Green phases last Cfg_GreenTime, amber phases last Cfg_AmberTime, and all-red phases last Cfg_AllRedTime.
- During every green or amber phase, the other direction is red. During each handover, both directions are red.