# AsyncIO RGB Blink

## Code

```python
"""
Raspberry Breadstick AsyncIO RGB Blink
Breadstick Innovations
March 26, 2024

This code uses the DotStar library to blink 3 of the SK9822 RGB LEDs, 
without time.sleep() based delays.
"""

from board import *
#from time import sleep
from adafruit_dotstar import DotStar
import asyncio

leds = DotStar(DOTSTAR_CLOCK, DOTSTAR_DATA, 24, brightness=0.02, auto_write=False)

RED = (255,0,0)
GREEN = (0,255,0)
BLUE = (0,0,255)
OFF = (0,0,0)

leds.fill(OFF)
leds.show()

async def blinker (led_num, color, frequency):
    
    period = 1/frequency
    global leds
    
    while True:
        leds[led_num] = color
        await asyncio.sleep(period)
        
        leds[led_num] = (0,0,0)
        await asyncio.sleep(period)
    

async def led_refresh (frequency):
    period = 1/frequency
    global leds
    
    while True:
        leds.show()
        await asyncio.sleep(period)
        
async def main():
    red = asyncio.create_task(blinker(0,RED,1))
    green = asyncio.create_task(blinker(12,GREEN,5))
    blue = asyncio.create_task(blinker(23,BLUE,9))
    refresh = asyncio.create_task(led_refresh(30))
    
    await red
    await green
    await blue
    await refresh
    
asyncio.run(main())
    


```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.breadstick.ca/breadstick/breadsticks/raspberry-breadstick/code-examples/asyncio-rgb-blink.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
