1. Light Up RGB LED Experiment
Less than 1 minute
Routine Code
from maix import GPIO
from modules import ws2812
import time
ws2812_obj = ws2812(6, 1)
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]
while True:
for color in colors:
ws2812_obj.set_led(0, color)
ws2812_obj.display()
time.sleep_ms(500)Experiment Preparation
- Connect the K210 to your computer via USB.
- Open CanMV IDE and run the routine code above.
Experiment Results
- After running, the RGB LED on the side of the K210 cycles through blue, green, and red every 500 ms.



Routine Code Explanation
- Import the modules required to run the routine.
from maix import GPIO
from modules import ws2812
import time- Create a WS2812 object to control addressable RGB LEDs. Parameters
(6, 1): pin 6 is the RGB LED pin;1means one WS2812 LED is controlled.
- Create a WS2812 object to control addressable RGB LEDs. Parameters
ws2812_obj = ws2812(6, 1)- Define a list of three colors: red, green, and blue. Each color is a tuple of three RGB channel values.
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]- Enter an infinite loop.
while True:- Iterate over each color in the
colorslist.
- Iterate over each color in the
for color in colors:- Set the color of the WS2812 LED at index 0 to the current color. Index 0 is used because only one LED is controlled.
ws2812_obj.set_led(0, color)- Call
ws2812_obj.display()to apply the color change.
- Call
ws2812_obj.display()time.sleep_ms(500)pauses for 500 milliseconds so each color is visible before switching.
time.sleep_ms(500)