Appearance
Example Recipes
This section demonstrates typical automation tasks. These examples combine functions and blocks into complete programs, providing practical templates that can easily be adapted.
Blinking Light (TON + NOT)
Goal: A light blinks at a 1‑second interval.
Blocks: TON, NOT.
vb
PROGRAM
DIM T AS TON
DIM led AS BOOL = FALSE
T(IN = TRUE, PT = T#1000ms)
IF T.Q THEN
led = NOT led
T(IN = FALSE, PT = T#1000ms)
END IF
PRINT led
END PROGRAMStaircase Lighting (TOF)
Goal: Light remains on for 30 seconds after button press.
Blocks: TOF.
vb
PROGRAM
DIM T AS TOF
DIM button AS BOOL = TRUE 'Value could come e.g. from an Input %I0
T(IN = button, PT = T#30s)
PRINT T.Q
END PROGRAMPulse Counter (CTU)
Goal: Each button press increments a counter; after 5 pulses print “Done”.
Blocks: CTU.
vb
PROGRAM
DIM C AS CTU
DIM button AS BOOL = TRUE 'Value could come e.g. from an Input %I0
C(CU = button, PV = 5)
PRINT "Count=", C.CV, " Done=", C.Q
END PROGRAMEdge‑Triggered Counting (R_TRIG + CTU)
Goal: Count only rising edges, not static signals.
Blocks: R_TRIG, CTU.
vb
PROGRAM
DIM F AS R_TRIG
DIM C AS CTU
DIM clk AS BOOL = TRUE 'Value could come e.g. from an Input %I0
F(CLK = clk)
IF F.Q THEN
C(CU = TRUE, PV = 3)
END IF
PRINT C.CV, C.Q
END PROGRAMTemperature Limiting (LIMIT)
Goal: Clamp temperature to range 0‑100 °C and issue a message if exceeded.
Blocks: LIMIT, IF.
vb
PROGRAM
DIM temp AS INT = 120
DIM safe AS INT
safe = LIMIT(0,temp,100)
PRINT safe
IF temp > 100 THEN
PRINT "Alarm: Overtemperature"
END IF
END PROGRAMExercises with Solutions
Task 1: Blinking light with 2‑second interval.
vb
PROGRAM
DIM T AS TON
DIM led AS BOOL = FALSE
T(IN = TRUE, PT = T#2000ms)
IF T.Q THEN
led = NOT led
T(IN = FALSE, PT = T#2000ms)
END IF
PRINT led
END PROGRAMTask 2: Staircase light with 10‑second timeout.
vb
PROGRAM
DIM T AS TOF
DIM button AS BOOL = TRUE 'Value could come e.g. from an Input %I0
T(IN = button, PT = T#10s)
PRINT T.Q
END PROGRAMTask 3: Counter with threshold 3, print “Alarm” when triggered.
vb
PROGRAM
DIM C AS CTU
DIM button AS BOOL = TRUE 'Value could come e.g. from an Input %I0
C(CU = button, PV = 3)
IF C.Q THEN
PRINT "Alarm"
END IF
END PROGRAM