Initial commit

This commit is contained in:
2025-01-18 16:26:30 +13:00
parent 2aa7cd038c
commit c3fb9566da
22 changed files with 3005 additions and 0 deletions

54
src/main.py Normal file
View File

@@ -0,0 +1,54 @@
import asyncio
from settings import Settings
from web import web
from patterns import Patterns
import gc
import utime
import machine
import ntptime
import time
import wifi
async def main():
settings = Settings()
patterns = Patterns(4, settings["num_leds"], selected=settings["selected_pattern"])
patterns.set_color1(tuple(int(settings["color1"][i:i+2], 16) for i in (1, 5, 3)))
patterns.set_color2(tuple(int(settings["color2"][i:i+2], 16) for i in (1, 5, 3)))
patterns.set_brightness(int(settings["brightness"]))
patterns.set_delay(int(settings["delay"]))
w = web(settings, patterns)
print(settings)
# start the server in a bacakground task
print("Starting")
server = asyncio.create_task(w.start_server(host="0.0.0.0", port=80))
wdt = machine.WDT(timeout=10000)
async def tick():
while True:
patterns.tick()
await asyncio.sleep_ms(1)
asyncio.create_task(tick())
first = True
while True:
#print(time.localtime())
# gc.collect()
for i in range(60):
wdt.feed()
await asyncio.sleep_ms(500)
# cleanup before ending the application
await server
asyncio.run(main())