Programming - First steps
P.
55 of 349
As in any other
programming language:
Counter=1
Supplement: Astro function
Day or night?
Variant 2: Press again
An ONE-edge starts the delay timer.
EmptyString
for the convert function is not evaluated. It merely serves to define the data type for the conversion.
Therefore, at this positions,
write
('1/2/2'c14,
convert
(Counter,$ $)) is also a possible solution.
The following special feature in the program may still seem incomprehensible to you:
if event('1/0/0'b01) and (SwitchingOperation==OFF) then \\
SwitchingOperation=ON; \\
write('1/1/1'b01,ON); \\
Counter=1u32\\
endif
Why is the event function linked to the variable
SwitchingOperation
in the if-statement? If this were not the case, a
telegram would be written on bus at each
event
('1/0/0'b01) and the
Counter
is increased. In our task, we want to
determine the number of cycles with activated lamp, but not the number of switching operations.
Therefore, we have to 'interlock' the
event
function in the
if
statement.
Another useful feature is the
sun
function: It returns the value
ON
(1b01) when the sun rises or
OFF
(0b01) if it is set (see also pages 184 and 150).
Turning to
Variant 2
. For the light circuit, the timer is to be restarted again, it the light switch is
pressed again.
Therefore we need:
delay(
Signal {Type b01}, Time in ms {Type u64}
)
The
delay
function requires a variable or an expression of binary type (type b01, for data types, see
also page 35 and 151 and the following) as the first argument. The function
delay
lags that
ON
impulse of the input for the time specified in the second argument. The type of the return value is
ON
or
OFF
. This can be quite clearly represented graphically by Figure 16. The second argument is of
type integer, 64-bit unsigned, thus we need the data type u64.
t
t
Signal
Delay
Time in ms
Time in
ms
Time in ms
Restart Timer
Figure 16: delay-function
However, our program has to be changed only at one point, and we have only to replace
after
with
delay
.
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]