[英]Changing neopixels randomly between 3 colors, on each pixel randomly
所以我目前有 2 个 12 像素 Neopixel 环,从 pi 零 W 运行。
LED 都按预期工作,经过电平转换器等,并按预期做出反应。
使用 python 的总菜鸟,但我可以控制像素并让它们做我想做的事情,但是我目前希望每个环上的每个像素随机在 3 组颜色之间随机切换。 基本上具有闪烁效果,但仅限于该颜色范围。
目前我只是在一个函数中手动更改每个像素,该函数从我的脚本中调用,循环一定时间。 它工作正常,但有点不优雅。
def Lights_Flicker():
pixels[0] = (255, 0, 0,0)
pixels.show()
time.sleep(.02)
pixels[12] = (255, 0, 0,0)
pixels.show()
time.sleep(.02)
pixels[6] = (122, 100, 0,0)
pixels.show()
time.sleep(.02)
pixels[23] = (122, 100, 0,0)
pixels.show()
time.sleep(.02)
使用它来循环函数 x 秒。 (播放声音时)
while time.time() < t_end:
Lights_Flicker()
我对计时部分很满意,只是颜色闪烁。 如果有人知道如何更干净地做到这一点,那就太棒了。
感谢您的关注
我相信这样的事情应该做你所要求的......
from random import randint
colors = [ (255,0,0,0), # put all color tuples here
(122,100,0,0),
]
pixel_num = [ 0, # put all pixels here
6,
12,
23,
]
while time.time() <= t_end:
rand_pixel = randint(0, len(pixel_num)-1)
rand_color = randint(0, len(colors)-1)
new_pixel = pixel_num[rand_pixel]
new_color = colors[rand_color]
pixels[new_pixel] = new_color
pixels.show()
time.sleep(0.02)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.