Firmware · Program structure and state machines
Devices with several modes are easier to get right when the mode is stored in one clear variable rather than a handful of flags.