# NeoPixels Rainbow on MicroPython
# Wokwi Example https://wokwi.com/arduino/projects/305569065545499202
from machine import Pin
from neopixel import NeoPixel
from time import sleep
# 定義16顆LED燈
pixels = NeoPixel(Pin(2), 16)
# 彩虹顏色的RGB值
rainbow_colors = [
(255, 0, 0), # Red
(255, 127, 0), # Orange
(255, 255, 0), # Yellow
(0, 255, 0), # Green
(0, 0, 255), # Blue
(75, 0, 130), # Indigo
(148, 0, 211), # Violet
]
# 重複循環彩虹顏色
while True:
for color in rainbow_colors:
# 所有16顆LED顯示相同的顏色
for i in range(16):
pixels[i] = color
# 更新顯示
pixels.write()
# 等待1秒
sleep(1)