Modelling a metronome and debouncing buttons
This lecture introduces the concept of the finite state machine (FSM or state machine for short). Many practical systems, audio-related and otherwise, can be modelled as state machines. This lecture presents applications to a metronome which marks the bar lines and various forms of sensor de-noising. It lays the groundwork for the ADSR envelope to be covered in a later lecture.
Table of contents
Lecture 13: State Machines
What you’ll learn in this lecture
- Structure and uses of state machines
- Debouncing buttons
What you’ll make in this lecture
- Metronome which marks the bar lines
- Button debouncer
- Comparator with hysteresis
metronome-envelope: Update to the metronome project from Lecture 9 which generates the tick sound using an exponential envelope instead of an audio file. In the lecture, this is extended to have a different pitch for the first beat of the bar.
scope-button: Simple example which displays the value of a digital input on the Bela oscilloscope.
debounce: Template project for implementing a state machine to debounce a push button.
hysteresis-comparator: Implements a simple comparator, with the task in the lecture to add hysteresis (variable threshold) for noise immunity.
Running the examples in this course assumes that you have a Bela Starter Kit or Bela Mini Starter Kit.
- Solderless breadboard (Rapid, Adafruit)
- 1x pushbutton (Rapid, Adafruit)
- 1x force-sensing resistor (Rapid, Adafruit)
- 1x LED (any colour) (Rapid, Adafruit)
- 1x 10k resistor (Rapid, Adafruit)
- 1x 220 ohm resistor (Rapid, Adafruit)
- Jumper wires (Rapid, Adafruit)