import uasyncio as asyncio
from machine import Pin
# Set up the LED and buzzer
led = Pin(2, Pin.OUT)
buzzer = Pin(14, Pin.OUT)
async def blink_led():
"""Asynchronous function to blink the LED."""
while True:
led.value(not led.value()) # Toggle LED state
await asyncio.sleep(0.5) # Wait for 0.5 seconds
async def beep_buzzer():
"""Asynchronous function to beep the buzzer."""
while True:
buzzer.on() # Turn buzzer on
await asyncio.sleep(0.2) # Beep for 0.2 seconds
buzzer.off() # Turn buzzer off
await asyncio.sleep(1) # Wait 1 second before the next beep
async def main():
# Create and run the asynchronous tasks
asyncio.create_task(blink_led())
asyncio.create_task(beep_buzzer())
# Keep the main loop running
while True:
await asyncio.sleep(1)
# Run the main function
asyncio.run(main())