|
楼主 |
发表于 2020-4-19 15:50
|
显示全部楼层
9、24位流动RGB彩虹灯环
[mw_shl_code=arduino,true]#MicroPython动手做(13)——掌控板之RGB三色灯
#24位流动RGB彩虹灯环
from mpython import *
import neopixel
import time
my_rgb = neopixel.NeoPixel(Pin(Pin.P8), n=24, bpp=3, timing=1)
def make_rainbow(_neopixel, _num, _bright, _offset):
_rgb = ((255,0,0), (255,127,0), (255,255,0), (0,255,0), (0,255,255), (0,0,255), (136,0,255), (255,0,0))
for i in range(_num):
t = 7 * i / _num
t0 = int(t)
r = round((_rgb[t0][0] + (t-t0)*(_rgb[t0+1][0]-_rgb[t0][0]))*_bright)>>8
g = round((_rgb[t0][1] + (t-t0)*(_rgb[t0+1][1]-_rgb[t0][1]))*_bright)>>8
b = round((_rgb[t0][2] + (t-t0)*(_rgb[t0+1][2]-_rgb[t0][2]))*_bright)>>8
_neopixel[(i + _offset) % _num] = (r, g, b)
offset = 0
while True:
make_rainbow(my_rgb, 24, 10, offset)
offset = offset + 1
my_rgb.write()
time.sleep_ms(100)[/mw_shl_code]
|
|