// 主程序
PROGRAM MAIN
VAR
lightCtrlData : LightControlData;
BEGIN
Init(lightCtrlData);
WHILE TRUE DO
ShiftPattern(lightCtrlData);
UpdateLights(lightCtrlData);
Delay(lightCtrlData.delayTime);
END_WHILE
END_PROGRAM
// 图案移位功能块
FUNCTION_BLOCK ShiftPattern (VAR_IN_OUT lightCtrlData : LightControlData)
VAR
newPattern : INT;
BEGIN
IF lightCtrlData.currentPattern < lightCtrlData.patternCount THEN
lightCtrlData.currentPattern := lightCtrlData.currentPattern + 1;
ELSE
lightCtrlData.currentPattern := 1;
END_IF
CASE lightCtrlData.currentPattern OF
1: ShiftLeft(lightCtrlData.lightStatus);
2: ShiftRight(lightCtrlData.lightStatus);
3: RotateLeft(lightCtrlData.lightStatus);
4: RotateRight(lightCtrlData.lightStatus);
END_CASE
END_FUNCTION_BLOCK
// 更新彩灯状态功能块
FUNCTION_BLOCK UpdateLights (VAR_IN_OUT lightCtrlData : LightControlData)
VAR
i : INT;
BEGIN
FOR i := 1 TO 8 DO
Q(i) := lightCtrlData.lightStatus;
END_FOR
END_FUNCTION_BLOCK
// 延时功能块
FUNCTION_BLOCK Delay (VAR_IN OUT timeOut : TIME; VAR_IN delay : TIME)
VAR
t : TIME;
BEGIN
t := t + T#100MS;
IF t >= delay THEN
t := T#0S;
timeOut := T#1S;
END_IF
END_FUNCTION_BLOCK