This commit is contained in:
janeptrv 2020-11-06 20:22:15 -05:00
parent 4e84992148
commit 2b8abfc4c6

34
leds.py
View file

@ -244,8 +244,8 @@ class Adafruit_CharLCD:
else:
self.write4bits(ord(char), True)
def defaultPattern(n):
return (n % 255, n % 255, n % 255)
def defaultPattern(n, t):
return ((n + t) % 255, (n + t) % 255, (n + t) % 255)
class LightStrip:
def __init__(self, data_pin = board.D18, string_length = 300, brightness = 1, pixel_order = neopixel.GRB):
@ -254,17 +254,22 @@ class LightStrip:
self.np = neopixel.NeoPixel(data_pin, string_length, brightness = brightness, auto_write=False, pixel_order = pixel_order)
self.pattern = defaultPattern
self.tick = 0
def set_light_level(self, level):
self.np.brightness = level
def pattern(self, pattern_callback):
self.pattern = pattern_callback
def tick(self):
np = self.np
t = self.tick
n = np.n
for i in range(n):
col = self.pattern(i)
col = self.pattern(i, t)
if np[i] != col:
np[i] = col
self.tick = t + 1
debug_statements = True
@ -285,17 +290,12 @@ def querylightlevel():
return 7
def color(lcd, col):
def color(lcd):
lcd.clear()
lcd.message("new color:\n#{}".format(col))
lcd.message("new pattern loaded.")
debug("NYI")
def querycolor():
debug("NYI")
return "ffffff"
def loop():
lcd = Adafruit_CharLCD()
lights = LightStrip()
@ -303,22 +303,16 @@ def loop():
level_max = 14
idle = 0
idle_max = 15
cur_color = "ffffff"
cur_color = (255, 255, 255)
while True:
debug("loop")
query_color = querycolor()
query_level = querylightlevel()
idle = idle + 1
debug("idle value: {}".format(idle))
if query_color != cur_color:
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
lcd.display()
ccolor = query_color
idle = 0
color(lcd, cur_color)
elif query_level != level:
lights.tick()
if query_level != level:
level = query_level
lights.set_light_level(level / level_max)
idle = 0
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
lcd.display()