“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.

../_images/48cc275fcaa1ddaa0a317d315d5b1638

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:

../_images/462ee5a7caa206200a317d3158d18528

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:

../_images/dd9a1736caa2210f0a317d3123be847a

The EXIT transition checks whether the counter is greater than a certain value, for example 7:

../_images/004b6231caa23f870a317d3121e01919

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:

../_images/ea302858caa25ad40a317d3144be8ebe