“SEQUENCE” second expansion level¶
In order to ensure that our diagram has at least one alternative branch, and so that we can turn off our traffic light unit at night, we now include in our program a counter which, after a certain number of TRAFFICSIGNAL cycles, turns the unit off.
At first we need a new variable COUNTER of the type INT. Declare this as usual in the declaration part of SEQUENCE, and initialize it in Init with 0.
Now select the Transition / Transition condition after Switch1 and insert a step and then a transition. Select the resulting transition and insert an alternative branch to its left. After the left transition insert a step and a transition. After the resulting new transition insert a jump after Switch1.
Name the new parts as follows: the upper of the two new steps should be called “Count” and the lower “Off”. The transitions are called (from top to bottom and from left to right) EXIT, TRUE and DELAY.OK. The new part should look like the part marked with the black border in the following image:
Now two new Action and a new Transition / Transition condition are to be implemented. At the step Count the variable COUNTER is increased by one:
The EXIT transition checks whether the counter is greater than a certain value, for example 7:
At Off the state of both lights is set at 5(OFF), (or each other number not equal 1,2,3 or 4) the COUNTER is reset to 0, and a time delay of 10 seconds is set: