Added neopixel on rotary encoder breakout board for user feedback

This commit is contained in:
David Thurstenson 2023-08-10 09:41:36 -05:00
parent 6800d0eb7a
commit c2deee3ebd
1 changed files with 19 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import board
import neopixel import neopixel
import adafruit_datetime as datetime import adafruit_datetime as datetime
from adafruit_seesaw import seesaw, rotaryio, digitalio from adafruit_seesaw import seesaw, rotaryio, digitalio
from adafruit_seesaw import neopixel as seesaw_neopixel
from adafruit_debouncer import Button from adafruit_debouncer import Button
import busio import busio
import displayio import displayio
@ -85,16 +86,24 @@ pixels = neopixel.NeoPixel(
pixel_order="GRBW" pixel_order="GRBW"
) )
# Set up user-facing neopixel on rotary breakout
userpixel = seesaw_neopixel.NeoPixel(seesaw, 6, 1,
brightness=brightness,
auto_write=False)
# Colors used in this script # Colors used in this script
# FORMAT: (R, G, B, W) # FORMAT: (R, G, B, W)
RED = (255, 0, 0, 0) RED = (255, 0, 0, 0)
YELLOW = (255, 150, 0, 0) YELLOW = (255, 150, 0, 0)
GREEN = (0, 255, 0, 0) GREEN = (0, 255, 0, 0)
BLANK = (0, 0, 0) BLANK = (0, 0, 0, 0)
# Turn all pixels off # Turn all pixels off
pixels.fill(BLANK) pixels.fill(BLANK)
pixels.show() pixels.show()
userpixel.fill(BLANK)
userpixel.show()
# END Neopixel setup # END Neopixel setup
#### ####
@ -182,6 +191,8 @@ def countdown(
# Turn all pixels off # Turn all pixels off
pixels.fill(BLANK) pixels.fill(BLANK)
pixels.show() pixels.show()
userpixel.fill(BLANK)
userpixel.show()
# Init the update interval tracking variable # Init the update interval tracking variable
last_update_time = -1 last_update_time = -1
@ -228,6 +239,7 @@ def countdown(
# Light the first LED when the timer starts # Light the first LED when the timer starts
# regardless of other factors # regardless of other factors
colorizer(0, colormode) colorizer(0, colormode)
userpixel.fill(GREEN)
elif current_position == num_pixels and current_time > 0: elif current_position == num_pixels and current_time > 0:
# If current_position calls for *all* # If current_position calls for *all*
# pixels to be lit, and the timer # pixels to be lit, and the timer
@ -248,14 +260,18 @@ def countdown(
pass pass
elif current_time <= redtime: elif current_time <= redtime:
colorizer(pixel, colormode, red=True) colorizer(pixel, colormode, red=True)
userpixel.fill(RED)
elif current_time <= yellowtime: elif current_time <= yellowtime:
colorizer(pixel, colormode, yellow=True) colorizer(pixel, colormode, yellow=True)
userpixel.fill(YELLOW)
else: else:
colorizer(pixel, colormode) colorizer(pixel, colormode)
userpixel.fill(GREEN)
# All the pixels have now been set based on the # All the pixels have now been set based on the
# specified colormode, now display the result IRL. # specified colormode, now display the result IRL.
pixels.show() pixels.show()
userpixel.show()
# Increment the elapsed time variable # Increment the elapsed time variable
current_time -= update_interval current_time -= update_interval
@ -328,3 +344,5 @@ while True:
# Turn off all pixels # Turn off all pixels
pixels.fill(BLANK) pixels.fill(BLANK)
pixels.show() pixels.show()
userpixel.fill(BLANK)
userpixel.show()