kopia lustrzana https://github.com/micropython/micropython
examples/hwapi: Rename uasyncio to asyncio.
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>pull/11740/head
rodzic
9092909bf5
commit
d975bb1f27
|
@ -1,6 +1,6 @@
|
||||||
# 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):
|
||||||
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):
|
||||||
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()
|
|
@ -1,5 +1,5 @@
|
||||||
# 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):
|
||||||
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):
|
||||||
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))
|
Ładowanie…
Reference in New Issue