up btn test

This commit is contained in:
Tomas Krejci 2024-05-21 23:34:37 +02:00
parent f62b163990
commit 4d2a013330
2 changed files with 22 additions and 14 deletions

View File

@ -14,7 +14,7 @@ import uasyncio as asyncio
from primitives.delay_ms import Delay_ms
import primitives.queue as queue
from primitives import Switch, Pushbutton
import rgb.py as rgb
from rgb import RGB
# Settings
@ -26,18 +26,21 @@ btn = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP)
# Pulse an LED (coroutine)
async def pulse(led, ms):
led.on()
await asyncio.sleep_ms(ms)
led.off()
# Pulse an LED when an event triggered
async def evt_pulse(event, led):
async def evt_pulse(event, rgb, set):
while True:
event.clear()
await event.wait()
led.on()
await asyncio.sleep_ms(500)
led.off()
# led.on()
await set()
await asyncio.sleep_ms(300)
# led.off()
await rgb.off()
# Toggle an LED (callback)
@ -57,18 +60,23 @@ async def killer(obj):
# Test for the Pushbutton class (events)
async def do_btn_event():
led.off()
#led.off()
rgb = RGB()
pb = Pushbutton(btn)
pb.press_func(None)
pb.release_func(None)
pb.double_func(None)
pb.long_func(None)
#tasks = []
#for event, led in ((pb.press, 1), (pb.release, 2), (pb.double, 3), (pb.long, 4)):
#tasks.append(asyncio.create_task(evt_pulse(pb.press, led)))
tasks = []
for event, rgb, set in ((pb.press, rgb, rgb.set_blue),
(pb.release, rgb, rgb.set_green),
(pb.double, rgb, rgb.set_yellow),
(pb.long, rgb, rgb.set_red)):
asyncio.create_task(evt_pulse(event, rgb, set))
#tasks.append(asyncio.create_task(evt_pulse(pb.double, led)))
asyncio.create_task(evt_pulse(pb.double, led))
#asyncio.create_task(evt_pulse(pb.double, rgb))
#await killer(pb)
#for task in tasks:

View File

@ -111,9 +111,9 @@ class RGB:
await self.set_red()
print("RGB power:", await self.get_pwr())
await uasyncio.sleep(sec)
rgb = RGB()
asyncio.run(rgb.test())
# test
#rgb = RGB()
#asyncio.run(rgb.test())