strips
This commit is contained in:
parent
4e84992148
commit
2b8abfc4c6
1 changed files with 14 additions and 20 deletions
34
leds.py
34
leds.py
|
@ -244,8 +244,8 @@ class Adafruit_CharLCD:
|
||||||
else:
|
else:
|
||||||
self.write4bits(ord(char), True)
|
self.write4bits(ord(char), True)
|
||||||
|
|
||||||
def defaultPattern(n):
|
def defaultPattern(n, t):
|
||||||
return (n % 255, n % 255, n % 255)
|
return ((n + t) % 255, (n + t) % 255, (n + t) % 255)
|
||||||
|
|
||||||
class LightStrip:
|
class LightStrip:
|
||||||
def __init__(self, data_pin = board.D18, string_length = 300, brightness = 1, pixel_order = neopixel.GRB):
|
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.np = neopixel.NeoPixel(data_pin, string_length, brightness = brightness, auto_write=False, pixel_order = pixel_order)
|
||||||
self.pattern = defaultPattern
|
self.pattern = defaultPattern
|
||||||
|
self.tick = 0
|
||||||
|
|
||||||
|
def set_light_level(self, level):
|
||||||
|
self.np.brightness = level
|
||||||
def pattern(self, pattern_callback):
|
def pattern(self, pattern_callback):
|
||||||
self.pattern = pattern_callback
|
self.pattern = pattern_callback
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
np = self.np
|
np = self.np
|
||||||
|
t = self.tick
|
||||||
n = np.n
|
n = np.n
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
col = self.pattern(i)
|
col = self.pattern(i, t)
|
||||||
if np[i] != col:
|
if np[i] != col:
|
||||||
np[i] = col
|
np[i] = col
|
||||||
|
self.tick = t + 1
|
||||||
|
|
||||||
debug_statements = True
|
debug_statements = True
|
||||||
|
|
||||||
|
@ -285,17 +290,12 @@ def querylightlevel():
|
||||||
return 7
|
return 7
|
||||||
|
|
||||||
|
|
||||||
def color(lcd, col):
|
def color(lcd):
|
||||||
lcd.clear()
|
lcd.clear()
|
||||||
lcd.message("new color:\n#{}".format(col))
|
lcd.message("new pattern loaded.")
|
||||||
debug("NYI")
|
debug("NYI")
|
||||||
|
|
||||||
|
|
||||||
def querycolor():
|
|
||||||
debug("NYI")
|
|
||||||
return "ffffff"
|
|
||||||
|
|
||||||
|
|
||||||
def loop():
|
def loop():
|
||||||
lcd = Adafruit_CharLCD()
|
lcd = Adafruit_CharLCD()
|
||||||
lights = LightStrip()
|
lights = LightStrip()
|
||||||
|
@ -303,22 +303,16 @@ def loop():
|
||||||
level_max = 14
|
level_max = 14
|
||||||
idle = 0
|
idle = 0
|
||||||
idle_max = 15
|
idle_max = 15
|
||||||
cur_color = "ffffff"
|
cur_color = (255, 255, 255)
|
||||||
while True:
|
while True:
|
||||||
debug("loop")
|
debug("loop")
|
||||||
query_color = querycolor()
|
|
||||||
query_level = querylightlevel()
|
query_level = querylightlevel()
|
||||||
idle = idle + 1
|
idle = idle + 1
|
||||||
debug("idle value: {}".format(idle))
|
debug("idle value: {}".format(idle))
|
||||||
|
lights.tick()
|
||||||
if query_color != cur_color:
|
if query_level != level:
|
||||||
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
|
|
||||||
lcd.display()
|
|
||||||
ccolor = query_color
|
|
||||||
idle = 0
|
|
||||||
color(lcd, cur_color)
|
|
||||||
elif query_level != level:
|
|
||||||
level = query_level
|
level = query_level
|
||||||
|
lights.set_light_level(level / level_max)
|
||||||
idle = 0
|
idle = 0
|
||||||
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
|
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
|
||||||
lcd.display()
|
lcd.display()
|
||||||
|
|
Loading…
Reference in a new issue