#导入Pin模块
from machine import Pin
from neopixel import NeoPixel
import time
#定义RGB控制对象
#控制引脚为16,RGB灯串联5个
rgb_num=4
rgb_led1=NeoPixel(Pin(16,Pin.OUT),rgb_num)
rgb_led2=NeoPixel(Pin(17,Pin.OUT),rgb_num)
#定义RGB颜色,相当于定义一个调色盘
RED = (255, 0, 0)
ORANGE = (255, 165, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
INDIGO = (75, 0, 130)
VIOLET = (138, 43, 226)
COLORS1 = (RED, ORANGE, YELLOW, GREEN, BLUE, INDIGO, VIOLET)
COLORS2 = (GREEN, BLUE, INDIGO, VIOLET, ORANGE, YELLOW)
while True:
for color1 in COLORS1:
for i in range(rgb_num):
rgb_led1[i]=(color1[0], color1[1], color1[2])
rgb_led1.write()
time.sleep_ms(100)
for color2 in COLORS2:
for n in range(rgb_num):
rgb_led2[n]=(color2[0], color2[1], color2[2])
rgb_led2.write()
time.sleep_ms(100)