繼續練習SCL程式設計,按照前面第2個練習的要求,使用SCL實現紅綠黃等倒數計時還有5秒進行閃爍。
前面程式新建一個SCL程式設計的FB,建立下面的變數
寫下面的SCL程式
IF #stopbtn = 1 THEN
#CurrentState := 4;
END_IF;
IF #startbrn = 1 THEN
#CurrentState := 1;
END_IF;
(*紅燈控制*)
IF #CurrentState = 1 THEN
#RedLight_in := 1;
IF NOT #RedLightsparkle THEN
#RedLight := 1;
ELSE
#RedLight := 0;
END_IF;
#RedLightTime:=T_SUB(IN1 := #RedLightDuration, IN2 := "RedLight_TON3".ET);(*計算剩餘時間*)
IF #RedLightTime <= t#5s AND "Clock_0.5Hz" THEN
#RedLightsparkle := 1;
ELSE
#RedLightsparkle := 0;
END_IF;
ELSE
#RedLight_in := 0;
#RedLight := 0;
END_IF;
"RedLight_TON4".TON(IN:=#RedLight_in,
PT:=#RedLightDuration);
IF "RedLight_TON3".Q THEN
#CurrentState := 2;
END_IF;
(*綠燈控制*)
IF #CurrentState = 2 THEN
#GreenLight_in := 1;
IF NOT #GreenLightsparkle THEN
#GreenLight := 1;
ELSE
#GreenLight := 0;
END_IF;
#GreenLightTime := T_SUB(IN1 := #GreenLightDuration, IN2 :="GreenLight_TON4".ET);(*計算剩餘時間*)
IF #GreenLightTime <= t#5s AND "Clock_0.5Hz" THEN
#GreenLightsparkle := 1;
ELSE
#GreenLightsparkle := 0;
END_IF;
ELSE
#GreenLight_in := 0;
#GreenLight := 0;
END_IF;
"GreenLight_TON4".TON(IN:=#GreenLight_in,
PT:=#GreenLightDuration);
IF "GreenLight_TON4".Q THEN
#CurrentState := 3;
END_IF;
(*黃燈控制*)
IF #CurrentState = 3 THEN
#yellowLight_in := 1;
IF NOT #YellowLightsparkle THEN
#YellowLight := 1;
ELSE
#YellowLight := 0;
END_IF;
#YellowLightTime := T_SUB(IN1 := #YellowLightDuration, IN2 := "YellowLight_TON4".ET);(*計算剩餘時間*)
IF #YellowLightTime <= t#5s AND "Clock_0.5Hz" THEN
#YellowLightsparkle := 1;
ELSE
#YellowLightsparkle := 0;
END_IF;
ELSE
#yellowLight_in := 0;
#YellowLight := 0;
END_IF;
"YellowLight_TON4".TON(IN := #yellowLight_in,
PT := #YellowLightDuration);
IF "YellowLight_TON4".Q THEN
#CurrentState := 1;
END_IF;
在OB1呼叫這個FB
在WINCC建立變數,關聯M1.6和M1.7,WINCC畫面放置按鈕,用於啟動停止功能,關聯前面建立的變數,滑鼠按下變數為1,滑鼠彈起變數為0
儲存執行wincc,啟動控制功能,就可以看到效果了。
WINCC這邊設定比較簡單,我就不做截圖了。