一、WS2812 和NeoPixel
Banana BPI-Pico-RP2040上的板载 WS2812 彩灯连接到GPIO 3引脚,由一个信号线控制。
class NeoPixel¶
This class stores pixel data for a WS2812 LED strip connected to a pin. The application should set pixel data and then call <span class="pre">NeoPixel.write()</span> when it is ready to update the strip.
二、代码
from machine import Pin
from neopixel import NeoPixel
import time
np = NeoPixel(Pin(3), 1)
r_code=[255,0,255,65,160,255,0,255,65]
g_code=[255,255,0,105,32,255,255,0,105]
b_code=[0,0,0,255,240,0,0,0,255]
while True:
for j in range(0,9,1):
np[0]=(r_code[j],g_code[j],b_code[j])
np.write()
time.sleep_ms(100)
三、效果
PICO
|