1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > esp32 micropython 控制ws2812 RGB灯带

esp32 micropython 控制ws2812 RGB灯带

时间:2019-07-24 01:59:10

相关推荐

esp32 micropython 控制ws2812 RGB灯带

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)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。