Introduction
A washing machine control sequence tells the machine what steps to do and when, so your clothes get clean automatically.
(* Example PLC program using ladder logic style pseudocode *) PROGRAM WashingMachine VAR StartButton: BOOL; FillWater: BOOL; Wash: BOOL; Rinse: BOOL; Spin: BOOL; Timer: INT; END_VAR (* Control sequence steps *) IF StartButton THEN FillWater := TRUE; Timer := 0; END_IF IF FillWater THEN Timer := Timer + 1; IF Timer >= 10 THEN (* 10 seconds to fill water *) FillWater := FALSE; Wash := TRUE; Timer := 0; END_IF END_IF IF Wash THEN Timer := Timer + 1; IF Timer >= 20 THEN (* 20 seconds washing *) Wash := FALSE; Rinse := TRUE; Timer := 0; END_IF END_IF IF Rinse THEN Timer := Timer + 1; IF Timer >= 15 THEN (* 15 seconds rinsing *) Rinse := FALSE; Spin := TRUE; Timer := 0; END_IF END_IF IF Spin THEN Timer := Timer + 1; IF Timer >= 10 THEN (* 10 seconds spinning *) Spin := FALSE; Timer := 0; END_IF END_IF END_PROGRAM
IF StartButton THEN
FillWater := TRUE;
Timer := 0;
END_IFIF FillWater THEN Timer := Timer + 1; IF Timer >= 10 THEN FillWater := FALSE; Wash := TRUE; Timer := 0; END_IF END_IF
IF Spin THEN Timer := Timer + 1; IF Timer >= 10 THEN Spin := FALSE; Timer := 0; END_IF END_IF
PROGRAM WashingMachine VAR StartButton: BOOL := TRUE; FillWater: BOOL := FALSE; Wash: BOOL := FALSE; Rinse: BOOL := FALSE; Spin: BOOL := FALSE; Timer: INT := 0; Step: STRING := "Idle"; END_VAR (* Simulate the washing machine control sequence *) FOR i := 1 TO 60 DO IF StartButton THEN FillWater := TRUE; Step := "Filling Water"; StartButton := FALSE; Timer := 0; END_IF IF FillWater THEN Timer := Timer + 1; IF Timer >= 10 THEN FillWater := FALSE; Wash := TRUE; Step := "Washing"; Timer := 0; END_IF END_IF IF Wash THEN Timer := Timer + 1; IF Timer >= 20 THEN Wash := FALSE; Rinse := TRUE; Step := "Rinsing"; Timer := 0; END_IF END_IF IF Rinse THEN Timer := Timer + 1; IF Timer >= 15 THEN Rinse := FALSE; Spin := TRUE; Step := "Spinning"; Timer := 0; END_IF END_IF IF Spin THEN Timer := Timer + 1; IF Timer >= 10 THEN Spin := FALSE; Step := "Done"; Timer := 0; END_IF END_IF (* Output current step and timer *) WriteLn(CONCAT("Second ", INT_TO_STRING(i), ": ", Step, " (Timer: ", INT_TO_STRING(Timer), ")")); END_FOR END_PROGRAM
step = 1
if step == 1 and timer_done:
step = 2
elif step == 2 and timer_done:
step = 3
elif step == 3 and timer_done:
step = 4
step after three timer_done events?if step == 1 and timer_done:
step = 2
if step == 2 and timer_done:
step = 3
if step == 3 and timer_done:
step = 4
Pass the test and this pattern moves unknown