From 4e84992148531d89699ba7dbd6e8998cf426411c Mon Sep 17 00:00:00 2001 From: janeptrv Date: Fri, 6 Nov 2020 20:12:24 -0500 Subject: [PATCH] light strips! --- leds.py | 26 +++++++++++++++++++++++++- requirements.txt | 3 ++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/leds.py b/leds.py index d0d1f44..44593c1 100644 --- a/leds.py +++ b/leds.py @@ -7,6 +7,8 @@ # from time import sleep +import board +import neopixel class Adafruit_CharLCD: @@ -53,7 +55,7 @@ class Adafruit_CharLCD: LCD_5x10DOTS = 0x04 LCD_5x8DOTS = 0x00 - def __init__(self, pin_rs=24, pin_e=23, pin_b=4, pins_db=[17, 25, 27, 22], pin_rgb=18, GPIO=None): + def __init__(self, pin_rs=24, pin_e=23, pin_b=4, pins_db=[17, 25, 27, 22], GPIO=None): # Emulate the old behavior of using RPi.GPIO if we haven't been given # an explicit GPIO interface to use if not GPIO: @@ -242,6 +244,27 @@ class Adafruit_CharLCD: else: self.write4bits(ord(char), True) +def defaultPattern(n): + return (n % 255, n % 255, n % 255) + +class LightStrip: + def __init__(self, data_pin = board.D18, string_length = 300, brightness = 1, pixel_order = neopixel.GRB): + # Emulate the old behavior of using RPi.GPIO if we haven't been given + # an explicit GPIO interface to use + + self.np = neopixel.NeoPixel(data_pin, string_length, brightness = brightness, auto_write=False, pixel_order = pixel_order) + self.pattern = defaultPattern + + def pattern(self, pattern_callback): + self.pattern = pattern_callback + + def tick(self): + np = self.np + n = np.n + for i in range(n): + col = self.pattern(i) + if np[i] != col: + np[i] = col debug_statements = True @@ -275,6 +298,7 @@ def querycolor(): def loop(): lcd = Adafruit_CharLCD() + lights = LightStrip() level = 0 level_max = 14 idle = 0 diff --git a/requirements.txt b/requirements.txt index 2b944ca..f2968ea 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -rpi_ws281x==4.2.5 \ No newline at end of file +rpi_ws281x==4.2.5 +adafruit-circuitpython-neopixel==6.0.0 \ No newline at end of file