To the uninitiated the words ‘State machine’ sound like something scarily big and complex. They aren’t (necessarily) and can be quite useful. In fact, state machines are no physical machines but a model of processes. They link the states a system can be in with allowed transitions. For example a media player when stopped can change to play or open another file. While playing, it can go to pause, stop, reverse, fast forward and so on. A state machine creates a map of all states and how they are connected. It is an abstract tool hat offers a graphical approach to organizing your code before actually programming.
In his video [Chris Guichet] uses a state machine to debounce a switch for a beginner friendly introduction of the concept. He then shows how to turn the hand drawn map to actual code, including a section on debugging state machines.
State machines are one of the tools that veterans wield easily but often have a hard time to explain to youngsters. This video solves this. For those that prefer to read, we have a thorough explanation in text form at hand. And of course a physical machine with blinkenlights.
“To the uninitiated the words ‘State machine’ sound like something scarily big and complex. ”
Only if they have a political affiliation.