Raspberry Pi Pico MicroPython exercise of using uasyncio:
"""
MicroPython uasyncio exercise on RP2040
"""
from sys import implementation
from os import uname
import uasyncio as asyncio
from machine import Pin
import utime
led = Pin(25, Pin.OUT)
print(implementation.name)
print(uname()[3])
print(uname()[4])
print()
print(asyncio.__name__)
print(asyncio.__version__)
#Toggle onboard LED every 500ms
async def asyncTask1():
while True:
led.toggle()
await asyncio.sleep_ms(500)
#print time every 1 second
async def asyncTask2():
while True:
print(utime.time())
await asyncio.sleep_ms(1000)
loop = asyncio.get_event_loop()
loop.create_task(asyncTask1())
loop.create_task(asyncTask2())
loop.run_forever()
print("- bye -")
~ More exercise on Raspberry Pi Pico
No comments:
Post a Comment