Basic Timer

An hourglass does one thing, count a fixed period time. We can do the same thing very easily with the Circuit Playground using the sleep() function from the time module. This function simply takes an amount of time, in seconds, and waits that amount of time.

1 second = 1000 milliseconds

So we can make a basic timer by turning on all of the NeoPixels, waiting the specified amount of time using sleep(), and then turning off all of the NeoPixels to indicate the time has elapsed.

Easy peasy lemony squeezy, here's the code to do that:

Download: file
# Circuit Playground Express Basic Timer
# Author: Carter Nelson
# MIT License (
import time
from import cpx

while True:
    # Turn ON all the NeoPixels
    cpx.pixels.fill((255, 255, 255))
    # Wait 5 seconds
    # Turn OFF all the NeoPixels
    cpx.pixels.fill((0, 0, 0))    
    # Wait for button press to reset timer
    while not cpx.button_a or cpx.button_b:
        pass # do nothing
This guide was first published on Dec 29, 2016. It was last updated on Dec 29, 2016. This page (Basic Timer) was last updated on Nov 29, 2017.