I just made my first steps with the uasyncio module in Micropython and I'm impressed. Here is a small example how to use coroutines for letting all 3 LEDs on the Pyboard v1.1 blink with different intervals. The resulting code is unexpectedly short but also readable.
import pyb import uasyncio as asyncio async def blink_led(led, interval_s): """Let the LED blink in the given interval.""" while True: await asyncio.sleep(interval_s) led.toggle() led_red = pyb.LED(1) # red led on the pyboard led_green = pyb.LED(2) # green led on the pyboard led_yellow = pyb.LED(3) # yellow led on the pyboard # get a new event loop loop = asyncio.get_event_loop() # create new tasks for each led loop.call_soon(blink_led(led_red, interval_s=0.5)) loop.call_soon(blink_led(led_green, interval_s=1)) loop.call_soon(blink_led(led_yellow, interval_s=2)) # run all tasks loop.run_forever()
For a comprehensive tutorial on Micropython async have a look at https://github.com/peterhinch/micropython-async.