收藏

micropython uasyncio 简单异步用法

分类: 基础知识篇 >> Micropython基础知识 发布于 2024-05-16 351次阅读0点赞0收藏
import uasyncio

async def blink(led, period_ms):
    while True:
        led.on()
        await uasyncio.sleep_ms(5)
        led.off()
        await uasyncio.sleep_ms(period_ms)

async def main(led1, led2):
    uasyncio.create_task(blink(led1, 700))
    uasyncio.create_task(blink(led2, 400))
    await uasyncio.sleep_ms(10_000)

# Running on a pyboard
from machine import Pin
uasyncio.run(main(Pin(12), Pin(13)))
VIP
购买
建议
意见
联系
客服
在线咨询

您可以与在线客服进行沟通获得帮助

工作日:8:00~22:00节假日:9:00~20:00

微信号: mpyos01

Q Q号: 1401211620

免费
福利
0.029118s