Led fan
This commit is contained in:
parent
2a7b5527a5
commit
b0c8a4371b
34
src/main.py
34
src/main.py
|
@ -10,6 +10,7 @@ import time
|
||||||
import wifi
|
import wifi
|
||||||
import json
|
import json
|
||||||
from p2p import p2p
|
from p2p import p2p
|
||||||
|
from machine import ADC, Pin
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
@ -22,18 +23,48 @@ async def main():
|
||||||
patterns.set_brightness(int(settings["brightness"]))
|
patterns.set_brightness(int(settings["brightness"]))
|
||||||
patterns.set_delay(int(settings["delay"]))
|
patterns.set_delay(int(settings["delay"]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def tick():
|
async def tick():
|
||||||
while True:
|
while True:
|
||||||
patterns.tick()
|
patterns.tick()
|
||||||
await asyncio.sleep_ms(0)
|
await asyncio.sleep_ms(0)
|
||||||
|
|
||||||
async def system():
|
async def system():
|
||||||
|
adc = ADC(Pin(2), atten=ADC.ATTN_11DB)
|
||||||
while True:
|
while True:
|
||||||
gc.collect()
|
gc.collect()
|
||||||
for i in range(60):
|
for i in range(60):
|
||||||
wdt.feed()
|
wdt.feed()
|
||||||
|
|
||||||
await asyncio.sleep(1)
|
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)
|
w = web(settings, patterns)
|
||||||
print(settings)
|
print(settings)
|
||||||
# start the server in a bacakground task
|
# start the server in a bacakground task
|
||||||
|
@ -45,8 +76,7 @@ async def main():
|
||||||
asyncio.create_task(tick())
|
asyncio.create_task(tick())
|
||||||
asyncio.create_task(p2p(settings, patterns))
|
asyncio.create_task(p2p(settings, patterns))
|
||||||
asyncio.create_task(system())
|
asyncio.create_task(system())
|
||||||
|
asyncio.create_task(sw())
|
||||||
|
|
||||||
|
|
||||||
# cleanup before ending the application
|
# cleanup before ending the application
|
||||||
await server
|
await server
|
||||||
|
|
Loading…
Reference in New Issue