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.
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:
# Circuit Playground Express Basic Timer
#
# Author: Carter Nelson
# MIT License (https://opensource.org/licenses/MIT)
import time
from adafruit_circuitplayground.express import cpx
while True:
# Turn ON all the NeoPixels
cpx.pixels.fill((255, 255, 255))
# Wait 5 seconds
time.sleep(5)
# 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
Page last edited November 17, 2017
Text editor powered by tinymce.