ws2812RGB灯带
==注意:==灯带需要三个线头都接好,然后程序输出控制后才能亮,只是正负极插好不会亮的
连接走线:
rgb灯带 ws2812
代码:
from machine import Pinfrom neopixel import NeoPixelimport utimepin = Pin(12, Pin.OUT)np=NeoPixel(pin,30) ##30表示RGB灯带上灯珠个数red = (255,0,0)blue=(0,0,255)green=(0,255,0)def show(color,num):for i in range(10*num,10*(num+1)):np[i] = colornp.write()utime.sleep(0.1)while True:for i in range(3):show(red,i)#utime.sleep(3)show(blue,i)#utime.sleep(3)show(green,i)#utime.sleep(3)
from machine import Pinfrom neopixel import NeoPixelimport utimepin = Pin(12, Pin.OUT)np=NeoPixel(pin,30)red = (255,0,0)blue=(0,0,255)green=(0,255,0)def show(color,num):"""灯带正序循环"""for i in range(num,30):np[i] = colornp.write()utime.sleep(0.05)def show1(color,num):"""灯带反向循环"""for i in range(num,30)[::-1]:np[i] = colornp.write()utime.sleep(0.05)while True:for i in range(1):show(red,i)#utime.sleep(3)show1(blue,i)#utime.sleep(3)show(green,i)#utime.sleep(3)show1(red,i)#utime.sleep(3)show(blue,i)#utime.sleep(3)show1(green,i)