From b0c8a4371bcfe632b7915389f6022c75ae0ab779 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 14 Aug 2025 17:01:31 +1200 Subject: [PATCH] Led fan --- src/main.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index 6e8c54c..25d6c61 100644 --- a/src/main.py +++ b/src/main.py @@ -10,6 +10,7 @@ import time import wifi import json from p2p import p2p +from machine import ADC, Pin async def main(): settings = Settings() @@ -22,18 +23,48 @@ async def main(): patterns.set_brightness(int(settings["brightness"])) patterns.set_delay(int(settings["delay"])) + + async def tick(): while True: patterns.tick() await asyncio.sleep_ms(0) async def system(): + adc = ADC(Pin(2), atten=ADC.ATTN_11DB) while True: gc.collect() for i in range(60): wdt.feed() + await asyncio.sleep(1) + async def sw(): + sw1 = machine.Pin(8, machine.Pin.IN, machine.Pin.PULL_UP) + sw2 = machine.Pin(9, machine.Pin.IN, machine.Pin.PULL_UP) + + p = ["on", "rainbow_cycle", "theater_chase", + "color_transition", "flicker", + "bidirectional_scanner"] + + pattern_index = 0 + + print(p) + pressed1 = 0 + pressed2 = 0 + while True: + if sw1.value() == 0: + patterns.select(p[pattern_index]) + print(p[pattern_index]) + pattern_index = pattern_index + 1 + if pattern_index > len(p)-1: + pattern_index = 0 + print("pressed 1") + if sw2.value() == 0: + patterns.select("off") + await asyncio.sleep_ms(200) + + w = web(settings, patterns) print(settings) # start the server in a bacakground task @@ -45,9 +76,8 @@ async def main(): asyncio.create_task(tick()) asyncio.create_task(p2p(settings, patterns)) asyncio.create_task(system()) - - - + asyncio.create_task(sw()) + # cleanup before ending the application await server