Understand a simple pattern recognition state machine expressed as an Arduino program using several idiomatic C/C++ program structures.
This is a very simple single-input binary pattern recognition system. However, even this state machine could be used to recognize synchronous inputs from a communications channel.
This graph represents the set of discrete states modelled by the system. States are illustrated as ovals and transitions as arrows. Each state can have an associated output, in this case the LED. Transitions between states are defined by condition rules.
Each transition has a one-second duration to make it feasible to manually manipulate the switch input with a timed sequence to walk through the graph. However, this makes it harder to read the graph. The same state machine with the wait states removed is simpler to read:
This same recognition exercise could be extended to any binary input: optical switches, wall contact switches. It could also be extended to any possible sampling rate, including cycling loop() as fast as possible.
The transition properties could be extended to include other predicates: comparisons on elapsed time to prevent exiting a state before time has elapsed, more elaborate mappings of linear inputs to transition state.
You may now recognize that the switch debouncing code introduced much earlier is a specific case of a finite-state machine implementing time-based hysteresis.
See InputMatcher1 Arduino Sketch, InputMatcher2 Arduino Sketch, and InputMatcher3 Arduino Sketch for code documentation.