Professional Documents
Culture Documents
Codes Ys
Codes Ys
Codes Ys
PROGRAM MAIN
VAR
timer: TP;
result: BOOL;
initFlag: BOOL;
END_VAR
VAR_INPUT
in1 AT %IX1.0: BOOL;
END_VAR
VAR_OUTPUT
out1 AT %QX1.0: BOOL;
END_VAR
(* =============================================== *)
timer(IN:=FALSE);
timer(IN:=TRUE);
END_IF
IL:
LD TRUE
AND in1
ST timer.IN
CAL timer(PT:=T#5000ms)
LD timer.Q
ST out1
Function-block header:
fbLEDButtonTimerReset[1](CLK := bLEDButton[1]);
IF fbLEDButtonTimerReset[1].Q THEN
tTimersOn[1](IN := FALSE);
tTimersOn[1].IN := TRUE;
tTimersOff[1](IN := FALSE);
END_IF
IF bLEDButton[1] THEN
tTimersOn[1]();
tTimersOff[1]();
fbLEDOffReset[1](CLK := tTimersOff[1].Q);
IF fbLEDOffReset[1].Q THEN
tTimersOn[1](IN := FALSE);
tTimersOn[1].IN := TRUE;
END_IF
fbLEDOnReset[1](CLK := tTimersOn[1].Q);
IF fbLEDOnReset[1].Q THEN
tTimersOff[1](IN := FALSE);
tTimersOff[1].IN := TRUE;
END_IF
PROGRAM PLC_PRG
VAR
xLed1 : ARRAY [1..6] OF BOOL; (* Array of LEDs *)
xLed1M : ARRAY [1..6] OF BOOL; (* Array of LEDs to remember what to blink*)
xLedButtons: ARRAY [1..6] OF BOOL; (* Array of buttons to toggle LED state *)
xLedButtonsM: ARRAY [1..6] OF BOOL; (* Array of button press memmories to use
pulse on rised edge of button press *)
i:INT;
xButtonBlink: BOOL; (* Button to press to start blinking *)
xButtonBlinkM: BOOL; (* Memory of the button state to detect raising edge *)
xBlinkLock: BOOL; (* Lock programm during blinking *)
xBlinkLockM: BOOL; (* Memory of the lock to detect raising and falling edge *)
fbTP1:TP; (* timer to enable lock for 6 seconds *)
fbBLINK1: BLINK;
END_VAR
(* Start lock timer of raising edge of blink button *)
fbTP1(IN := xButtonBlink AND NOT xButtonBlinkM, PT := T#6s);
xButtonBlinkM := xButtonBlink;
xBlinkLock := fbTP1.Q;