ST Examples
Every channel in IO Mapping is exposed as a global variable through its DefaultMapping name: IN0–IN6, OUT0–OUT5, AN0–AN2 and LED are usable directly, with no declaration and no mapping.
Blink the RGB LED red
Section titled “Blink the RGB LED red”LED is a DWORD in 0x00RRGGBB form, not a bit:
PROGRAM PLC_PRGVAR blinker : TON; xOn : BOOL;END_VAR
blinker(IN := NOT blinker.Q, PT := T#500ms);IF blinker.Q THEN xOn := NOT xOn; IF xOn THEN LED := 16#00FF0000; // red ELSE LED := 0; // off END_IFEND_IFFull brightness is harsh at close range; 16#00200000 is plenty for an indicator.
Colour by state
Section titled “Colour by state”PROGRAM PLC_PRGIF xFault THEN LED := 16#00FF0000; // redELSIF xConnected THEN LED := 16#0000FF00; // greenELSE LED := 16#00FFA000; // amber: running, not connectedEND_IFDigital pass-through
Section titled “Digital pass-through”PROGRAM PLC_PRGOUT0 := IN0;OUT1 := IN1;OUT2 := IN2;OUT3 := IN3;OUT4 := IN4;OUT5 := IN5;Analog threshold
Section titled “Analog threshold”PROGRAM PLC_PRGOUT0 := AN0 > 2048; // raw 12-bit count, 0...4095 over 0...3.3 VThere is no TEMPERATURE channel on this board — see IO Mapping.
Ask the modem its status
Section titled “Ask the modem its status”The complete pattern, including the GVL with the located variables, is on the Modem page:
CASE nStep OF0: GVL.sOut := 'AT+CFUN?'; GVL.wSend := 1; nStep := 1;1: GVL.wSend := 0; nStep := 2;2: IF GVL.wInLen > 0 THEN sResp := GVL.sIn; // e.g. '+CFUN: 4' then 'OK' nStep := 3; END_IFEND_CASE