← All exercises

Delayed Shutdown

medium

Hold the run-OK output high for a cooldown period after Stop is pressed.

What it teaches

Off-delay with a real-world framing: equipment runs, Stop fires, the output stays on for the cooldown, then drops. The twist: Start during cooldown cancels it and returns to running — that needs a small state machine (Stopped, Running, Cooldown), not just a bare off-delay timer.

Inputs and outputs

TagTypeDefaultDescription
In_StartBOOLStarts the equipment (1 = start)
In_StopBOOLStops the equipment (1 = stop)
Cfg_CooldownMsDINT5000Cooldown period in milliseconds
Out_RunBOOLEquipment run command

Required behavior

  • Equipment starts and Out_Run becomes 1 when In_Start is 1 and In_Stop is 0. Out_Run stays 1 after In_Start is released.
  • When In_Stop is 1, the equipment enters a cooldown phase if it was running. The cooldown continues after In_Stop is released.
  • During the cooldown phase, Out_Run remains 1.
  • After the cooldown timer reaches Cfg_CooldownMs, Out_Run becomes 0.
  • If In_Start is 1 during the cooldown phase and In_Stop is 0, the cooldown is cancelled and the equipment returns to normal running.