From 144e7d556fa032f5fdb4aa73411df1081ba86d68 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Fri, 26 Jan 2024 19:04:38 +0100 Subject: [PATCH] Implement rudimentary control for lightbar --- src/main.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main.py b/src/main.py index 4ee5017..cfd25b4 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,38 @@ +from machine import Pin +from neopixel import NeoPixel +import uasyncio + from lightbar.app import Lightbar +# TODO: Move this to config file +NEOPIXEL_COUNT = 28 + + +# TODO: Move this into a LightbarController class +async def run_neopixels(): + print('[main/run_neopixels] Turning on Neopixels') + np = NeoPixel(Pin(26), NEOPIXEL_COUNT) + np.fill((0, 0, 0)) + np.write() + + color_set = [ + (255, 0, 0), + (255, 255, 0), + (0, 255, 0), + (0, 255, 255), + (0, 0, 255), + (255, 0, 255), + ] + + while True: + for i in range(NEOPIXEL_COUNT): + np[i] = color_set[i % len(color_set)] + np.write() + + await uasyncio.sleep(0.5) + +uasyncio.create_task(run_neopixels()) + print('[main] Starting lightbar HTTP server...') api_server = Lightbar() api_server.run(port=80, debug=True)