Skip to content

Instantly share code, notes, and snippets.

@todbot
Created May 8, 2025 20:54
Show Gist options
  • Save todbot/da61cee8b2eb1382066dfe6afce9bd0e to your computer and use it in GitHub Desktop.
Save todbot/da61cee8b2eb1382066dfe6afce9bd0e to your computer and use it in GitHub Desktop.
simple asyncio demo of two LEDs using global variables
# simple asyncio demo of two LEDs using global variables
# 8 May 2025 - @todbot
import asyncio
import board
import digitalio
ledA = digitalio.DigitalInOut(board.GP25)
ledB = digitalio.DigitalInOut(board.GP0)
ledA.switch_to_output(value=False)
ledB.switch_to_output(value=False)
ledA_time = 0.3
ledB_time = 0.5
async def blink_A():
while True:
ledA.value = True
await asyncio.sleep(ledA_time)
ledA.value = False
await asyncio.sleep(ledA_time)
async def blink_B():
while True:
ledB.value = True
await asyncio.sleep(ledB_time)
ledB.value = False
await asyncio.sleep(ledB_time)
async def main():
ledA_task = asyncio.create_task(blink_A())
ledB_task = asyncio.create_task(blink_B())
await asyncio.gather(ledA_task, ledB_task)
print("done")
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment