leds/leds.py

71 lines
1.5 KiB
Python
Raw Normal View History

2020-11-03 23:51:13 +00:00
#!/usr/bin/env python
#
# based on code from lrvick and LiquidCrystal
# lrvic - https://github.com/lrvick/raspi-hd44780/blob/master/hd44780.py
# LiquidCrystal - https://github.com/arduino/Arduino/blob/master/libraries/LiquidCrystal/LiquidCrystal.cpp
#
from time import sleep
import lcd_manager
import light_manager
2020-11-03 23:51:13 +00:00
2020-11-04 01:44:08 +00:00
debug_statements = True
def debug(msg):
if debug_statements:
print(msg)
def lightlevel(lcd, level):
2020-11-04 01:44:08 +00:00
debug("display level")
lcd.clear()
lcd.message("Light Level:\n]" + "-"*level + "[")
2020-11-04 01:44:08 +00:00
def querylightlevel():
2020-11-04 01:44:08 +00:00
debug("NYI")
return 7
2020-11-07 01:22:15 +00:00
def color(lcd):
lcd.clear()
2020-11-07 01:22:15 +00:00
lcd.message("new pattern loaded.")
2020-11-04 01:44:08 +00:00
debug("NYI")
2020-11-03 23:51:13 +00:00
def loop():
lcd = lcd_manager.Adafruit_CharLCD()
lights = light_manager.LightStrip()
level = 0
2020-11-06 23:01:22 +00:00
level_max = 14
idle = 0
idle_max = 15
2020-11-07 01:22:15 +00:00
cur_color = (255, 255, 255)
while True:
2020-11-04 01:44:08 +00:00
debug("loop")
query_level = querylightlevel()
idle = idle + 1
2020-11-04 01:44:08 +00:00
debug("idle value: {}".format(idle))
lights.tick()
2020-11-07 01:22:15 +00:00
if query_level != level:
2020-11-04 01:44:08 +00:00
level = query_level
2020-11-07 01:22:15 +00:00
lights.set_light_level(level / level_max)
2020-11-04 01:44:08 +00:00
idle = 0
if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol:
lcd.display()
lightlevel(lcd, level)
2020-11-04 01:44:08 +00:00
elif idle >= idle_max:
debug("hit idle threshold")
idle = idle_max
lcd.noDisplay()
else:
lightlevel(lcd, level)
sleep(1)
2020-11-03 23:51:13 +00:00
if __name__ == '__main__':
loop()