IF bButton AND NOT ButtonOld  THEN
    wStep:=10;
END_IF;
CASE wStep OF 
 10:
     qLight1:=TRUE;
   IF TON1.Q THEN 
     qLight1:=FALSE;
     wStep:=20;
   END_IF;
 20:
  IF TON2.Q THEN 
     wStep:=30;
  END_IF;
 30:
     qLight2:=TRUE;
     IF TON3.Q THEN 
       qLight2:=FALSE;
        wStep:=40;
     END_IF;
  40:
    IF TON4.Q THEN 
        wStep:=50;
    END_IF;
  50:
    wCount:=wCount+1;
    IF wCount>=3 THEN
      wStep:=0;
     ELSE
       wStep:=10;
    END_IF;  
END_CASE;    
 
 
 
 
TON1(IN:= qLight1 ,PT:= T#3S);    
TON2(IN:= NOT qLight1 ,PT:= T#2S);
TON3(IN:= qLight2 ,PT:= T#3S);    
TON4(IN:= NOT qLight2 ,PT:= T#2S);
ButtonOld:=bButton;