Simple state machine. Public domain by Wikipedia user Cepheus

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:

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.


Featured Parts

Adafruit ItsyBitsy M4 Express featuring ATSAMD51 connected to a small breadboard.
What's smaller than a Feather but larger than a Trinket? It's an Adafruit ItsyBitsy M4 Express featuring the Microchip ATSAMD51! Small,...
Angled shot of a Adafruit Feather M4 Express.
It's what you've been waiting for, the Feather M4 Express featuring ATSAMD51. This Feather is fast like a swift, smart like an owl, strong like a ox-bird (it's half ox,...
Top down shot of a Adafruit Grand Central M4 Express featuring the SAMD51.
Are you ready? Really ready? Cause here comes the Adafruit Grand Central featuring the Microchip ATSAMD51. This dev board is so big, it's not...
Angled shot of a Adafruit Feather nRF52840 Express.
The Adafruit Feather nRF52840 Express is the new Feather family member with Bluetooth Low Energy and native USB support featuring the nRF52840!  It's...

This guide was first published on Dec 29, 2018. It was last updated on Jul 20, 2024.

This page (Overview) was last updated on Mar 08, 2024.

Text editor powered by tinymce.