提交 d975bb1f 编写于 作者: J Jim Mussared 提交者: Damien George

examples/hwapi: Rename uasyncio to asyncio.

This work was funded through GitHub Sponsors.
Signed-off-by: NJim Mussared <jim.mussared@gmail.com>
上级 9092909b
# Like soft_pwm_uasyncio.py, but fading 2 LEDs with different phase. # Like soft_pwm_asyncio.py, but fading 2 LEDs with different phase.
# Also see original soft_pwm.py. # Also see original soft_pwm.py.
import uasyncio import asyncio
from hwconfig import LED, LED2 from hwconfig import LED, LED2
...@@ -9,10 +9,10 @@ async def pwm_cycle(led, duty, cycles): ...@@ -9,10 +9,10 @@ async def pwm_cycle(led, duty, cycles):
for i in range(cycles): for i in range(cycles):
if duty: if duty:
led.value(1) led.value(1)
await uasyncio.sleep_ms(duty) await asyncio.sleep_ms(duty)
if duty_off: if duty_off:
led.value(0) led.value(0)
await uasyncio.sleep_ms(duty_off) await asyncio.sleep_ms(duty_off)
async def fade_in_out(LED): async def fade_in_out(LED):
...@@ -25,7 +25,7 @@ async def fade_in_out(LED): ...@@ -25,7 +25,7 @@ async def fade_in_out(LED):
await pwm_cycle(LED, i, 2) await pwm_cycle(LED, i, 2)
loop = uasyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.create_task(fade_in_out(LED)) loop.create_task(fade_in_out(LED))
loop.call_later_ms(800, fade_in_out(LED2)) loop.call_later_ms(800, fade_in_out(LED2))
loop.run_forever() loop.run_forever()
# See original soft_pwm.py for detailed comments. # See original soft_pwm.py for detailed comments.
import uasyncio import asyncio
from hwconfig import LED from hwconfig import LED
...@@ -8,10 +8,10 @@ async def pwm_cycle(led, duty, cycles): ...@@ -8,10 +8,10 @@ async def pwm_cycle(led, duty, cycles):
for i in range(cycles): for i in range(cycles):
if duty: if duty:
led.value(1) led.value(1)
await uasyncio.sleep_ms(duty) await asyncio.sleep_ms(duty)
if duty_off: if duty_off:
led.value(0) led.value(0)
await uasyncio.sleep_ms(duty_off) await asyncio.sleep_ms(duty_off)
async def fade_in_out(LED): async def fade_in_out(LED):
...@@ -24,5 +24,5 @@ async def fade_in_out(LED): ...@@ -24,5 +24,5 @@ async def fade_in_out(LED):
await pwm_cycle(LED, i, 2) await pwm_cycle(LED, i, 2)
loop = uasyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete(fade_in_out(LED)) loop.run_until_complete(fade_in_out(LED))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册