Hello guys, I am new at this forum and a beginner in codesys.
I am working on a small project, in which there are two lamps(Red L1, Green L2) and a button(T1).
The red lamp should be on for at least 5s and max 10s. If a button is pressed the red lamp should be off and th green lamp on after 3s.
The green phase should last for 5 s and then the red phase should start again.
I did write the following programm and no error is shown, but unfortunately it does not work. I would be really grateful for any kind of help
PROGRAM Aufgabe2 VAR state:UINT:=1; R_Trig_Taster:R_TRIG; timer3s:TON; timer5s:TON; timer10s:TON;
END_VAR
R_Trig_Taster(CLK:=GVL.T1);
CASE state OF 1://red phase GVL.L1:=TRUE; GVL.L2:=FALSE; timer5s(IN:=TRUE,PT:=T#5S); timer10s(IN:=TRUE,PT:=T#10S);
IF timer5s.Q=TRUE THEN WHILE timer10s.Q=FALSE DO
IF R_trig_Taster.Q=TRUE THEN timer3s(IN:=TRUE,PT:=T#3S); IF timer3s.Q=TRUE THEN state:=2; timer3s(IN:=FALSE,PT:=T#3S); timer5s(IN:=FALSE,PT:=T#5S); timer10s(IN:=FALSE,PT:=T#10S); END_IF
END_IF
END_WHILE
END_IF IF timer10s.Q=TRUE THEN state:=2; timer5s(IN:=FALSE,PT:=T#5S); timer10s(IN:=FALSE,PT:=T#10S);
2://green phase GVL.L1:=0; GVL.L2:=1; timer5s(IN:=TRUE,PT:=T#5S); IF timer5s.Q=TRUE THEN state:=1; timer5s(IN:=FALSE,PT:=T#5S); END_IF
END_CASE
Log in to post a comment.