Overview

circuitpython_640px-DFAexample.png
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

PRODUCT ID: 3800
What's smaller than a Feather but larger than a Trinket? It's an Adafruit ItsyBitsy M4 Express featuring the Microchip ATSAMD51! Small,...
$14.95
IN STOCK

Adafruit Feather M4 Express - Featuring ATSAMD51

PRODUCT ID: 3857
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,...
OUT OF STOCK

Adafruit Grand Central M4 Express featuring the SAMD51

PRODUCT ID: 4064
We're selling out fast but making more all the time! Sign up to be notified when it's in the store!Are you ready? Really ready? Cause here comes the...
OUT OF STOCK

Adafruit Feather nRF52840 Express

PRODUCT ID: 4062
The Adafruit Feather nRF52840 Express is the new Feather family member with Bluetooth Low Energy and native USB support featuring the nRF52840!  It's...
OUT OF STOCK
This guide was first published on Dec 29, 2018. It was last updated on Dec 29, 2018. This page (Overview) was last updated on Jul 19, 2019.