There's a standard way to draw state machines that can get quite detailed. Here we'll use a fairly basic form. Below is the state machine from the NYE ball drop guide. We'll explore a couple ways to implement it.

The rectangles are states, the lines between them are the transitions. Each conditional transition is labeled with the condition.

States are:
Waiting - The machine sits here waiting until the time read from the real time clock hardware reaches 10 seconds to midnight on Dec 31, or the switch being pressed.
Dropping - The ball is dropping, its NeoPixels are color cycling in a rainbow pattern, and the countdown sound clip is playing. Once the ball has finished dropping, Auld Lang Syne plays.
Burst - A random color is set on the NeoPixels and grows from black to full brightness, stops there for a bit before fading back to black. The effect is mean to look like a fireworks explosion.
Shower - A NeoPixel effect is portrayed that is meant to look like the shower of sparks falling after the initial explosion (using the same color).
Idle - Once the ball has dropped and the fireworks are over, the machine sits here indefinitely.
Paused - This is an interesting state. It is entered from most other states when the switch is pressed.  It is exited, returning from whence it came when the switch is pressed again. However, if the switch is held pressed for a over a second the Reset state is entered.
Reset - various machine state variables are reset in preparation for running through the sequence again.
Raising - The ball is raised again in preparation to be dropped. This continues for as long as the machine is in this state. Once the switch is released, the Waiting state is entered.

Some of transition conditions are based on hardware: pressed, released, have to with the switch. Others are a bit more abstract, e.g. fireworks finished which is true when the fireworks effect has run for the required amount of time.

We're going to look at two approaches to implementing state machines using this one as an example. It has some interesting challenges that make it a good case study.

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

This page (The NYE Ball Drop Machine) was last updated on Feb 19, 2021.

Text editor powered by tinymce.