Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickcjohnston/eda52933ba08a89967b8836828cc09a2 to your computer and use it in GitHub Desktop.
Save nickcjohnston/eda52933ba08a89967b8836828cc09a2 to your computer and use it in GitHub Desktop.
import board
import digitalio
import time
from adafruit_circuitplayground import cp
# Setup
cp.pixels.brightness = 0.5
seconds = 0
run_timer = False
# Temp Display
def thermometer():
# Get the temp
temp = cp.temperature
# Temp for the day is supposed to be
# -5C to +3C, so mod by 10
num_pix = int(temp % 10)
# print(num_pix)
# Set the colour to red if temp > 0
if temp > 0:
colour = (255, 0, 0)
# Set the colour to blue if temp < 0
elif temp < 0:
colour = (0, 0, 255)
else:
colour = (0, 255, 0)
# Colour 1 pixel for each degree C above or below 0
for pixel in range(num_pix):
cp.pixels[pixel] = colour
# print("Temperature C:", temp)
# Countdown Timer for Music
def timer(seconds):
#print("Seconds: ", seconds)
# Play a song after an hour
# to remind me to drink water
if seconds == 3600:
for f in (330, 349, 262, 294, 494, 523, 392, 440):
cp.play_tone(f, 0.25)
seconds = 0
return seconds, False
else:
# Increment seconds
seconds = seconds + 1
return seconds, True
# Main
while True:
# Check the slide switch position
# Run everything if it is on
if cp.switch:
# If we pressed a button start the timer
if cp.button_a or cp.button_b:
run_timer = True
# Increment seconds while the timer is running
# Also blink the small red led
if run_timer:
seconds, run_timer = timer(seconds)
cp.red_led = not cp.red_led
else:
cp.red_led = False
# Check the temp and display on the neopixels
thermometer()
# Sleep for 1 second
time.sleep(1)
# Turn off all the lights and wait 10 seconds if
# it is off to conserve power
else:
for pixel in range(10):
cp.pixels[pixel] = (0,0,0)
cp.red_led = False
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment