The author has used state machines in several CircuitPython guides, most recently for the New Years Eve dropping ball.
So what is a state machine?
Accoding to Wikipedia:
A finite-state machine (FSM) or finite-state automaton (FSA, plural: automata), finite automaton, or simply a state machine, is a mathematical model of computation. It is an abstract machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some external inputs; the change from one state to another is called a transition. An FSM is defined by a list of its states, its initial state, and the conditions for each transition.
So what's all that mean? Simply put, there's some number of states and a way to move between them.
What's a state? Let's use the example of the states of matter: solid. liquid, and gas (we'll ignore plasma to keep this simple). There are well defined transitions to move between these states:
- melting transitions from solid to liquid,
- freezing transitions from liquid to solid,
- evaporating transitions from liquid to gas,
- condensing transitions from gas to liquid, and
- sublimating transitions from solid to gas.
Each of these have conditions in terms of material, temperature, and pressure that control whether or not the transition can happen. A simplified example of this is that when its temperature is less than 0C (32F), water will freeze transitioning it from a liquid state to a solid state.
The state machine in the diagram at the top of this page processes a stream of 1s and 0s (as label the transitions). When the machine is in S1 it has processed an even number of 0s, and an odd number when in S2.
A huge advantage of working with a modern, capable MCU like the SAMD51 with it's ARM Cortex-M4 core and spacious memory is that we can make use of more advanced programming techniques that require overhead that smaller, simpler, slower MCUs simply can't handle.