Every real machine leans on the same handful of building blocks: a timer that waits, a state machine that decides, and the IEC languages you'll write them in. Try the first two below and watch them run.
A TON waits. Hold its input IN true and its elapsed time ET climbs toward the preset PT; when it gets there, the output Q goes true. Let go and the timer resets. Press and hold the button to see it.
tmr : TON; // call it every cycle tmr(IN := btnHeld, PT := T#3s); lampOn := tmr.Q; elapsed := tmr.ET;
💡 TOF delays the turn-off; TP fires a fixed-length pulse. You call both the same way as TON; only the timing behaviour changes.
A machine should always be in exactly one known state. A CASE on a state variable is the cleanest way to guarantee that. Step through this small start/run/stop cycle one state at a time.
CASE state OF 0: // IDLE IF startCmd THEN state := 1; END_IF; 1: // STARTING motor := TRUE; state := 2; 2: // RUNNING IF stopCmd THEN state := 3; END_IF; 3: // STOPPING motor := FALSE; state := 0; END_CASE;
A TON with PT := T#3s has had IN true for 1.2 s. What is Q?