In this guide we'll go through the steps to create an hourglass style timer with your Circuit Playground.

An hourglass is an ancient timing device used to measure a fixed amount of time. It contains two chambers separated by a thin neck that allows sand to pass from one chamber to the other very slowly. The overall size and amount of sand determines the amount of time. Once all the sand has emptied into one side, the hourglass is simply inverted to start counting time again.

Here, we'll use the NeoPixels on the Circuit Playground to represent the grains of sand in an hourglass, having them "disappear" one at a time by turning them off. We can even have the hourglass "reset" by turning the Circuit Playground over. We'll build this up one step at a time and walk through each one.

Required Parts

This project uses the sensors already included on the Circuit Playground, either a Classic or an Express. The only additional items needed are batteries for power and a holder for the batteries.

Before Starting

If you are new to the Circuit Playground, you may want to first read these overview guides.

Circuit Playground Classic

Circuit Playground Express

 

Arduino versions of the code are provided on the following pages.

The Arduino code on the following pages has been tested and verified to work on either a Circuit Playground Classic or Express.

CircuitPython

CircuitPython versions of the code are provided on the following pages.

CircuitPython only works on the Circuit Playground Express.

Questions and Code Challenges

The following are some questions related to this project along with some suggested code challenges. The idea is to provoke thought, test your understanding, and get you coding!

While the sketches provided in this guide work, there is room for improvement and additional features. Have fun playing with the provided code to see what you can do with it.

Questions

  • How would this code behave if the Circuit Playground had more than 10 NeoPixels? How about less?
  • What is the maximum amount of time that the timer can be set for?
  • Why is delay() or time.sleep() called before setting the NeoPixel colors in the loop?
  • For the Arduino version, why were floats used in the Fading Hourglass sketch for the RGB values? (hint: what does int value = 5/3; give?) In CircuitPython, what's the difference between evaluating 5 / 3 and 5 // 3?

Code Challenges

  • Use playTone() or cpx.play_tone() to add an audio alarm when the countdown ends.
  • Change the fade effect to be non-linear.
  • Allow for a flip reset during the count period.
This guide was first published on Dec 29, 2016. It was last updated on Dec 29, 2016.