Traffic Light Simple
medium
Drive a one-way traffic light through red, green, and amber phases on a timer.
What it teaches
Move through a fixed sequence of steps — red, then green, then amber, then back to red — each step held for a set time. A 'state machine': the program remembers which step it's on and switches to the next when the timer runs out. The skeleton behind every wash cycle, batch process, and motion routine.
Inputs and outputs
| Tag | Type | Default | Description |
|---|---|---|---|
| In_Enable | BOOL | 1 | — |
| Cfg_RedTime | DINT | 5000 | — |
| Cfg_GreenTime | DINT | 5000 | — |
| Cfg_AmberTime | DINT | 2000 | — |
| Out_Red | BOOL | — | — |
| Out_Green | BOOL | — | — |
| Out_Amber | BOOL | — | — |
Required behavior
- When In_Enable is 0, the sequence is disabled and outputs revert to Out_Red=1, Out_Green=0, Out_Amber=0.
- When In_Enable is 1, outputs cycle endlessly through Red, Green, and Amber states.
- Red phase lasts for Cfg_RedTime milliseconds, asserting Out_Red.
- Green phase lasts for Cfg_GreenTime milliseconds, asserting Out_Green.
- Amber phase lasts for Cfg_AmberTime milliseconds, asserting Out_Amber.