RainbowLight
-
カラーモデル
0 : 赤
85 : 緑
170: 青
255: 赤0 ~ 85 => 赤 ~ 緑
85 ~170 => 緑 ~ 青
170~255 => 青 ~ 赤
from machine import Pin
from neopixel import myNeopixel
import time
NUM_LEDS = 8
np = myNeopixel(NUM_LEDS, 16)
red = 0 #red
green = 0 #green
blue = 0 #blue
# 255を2色で分ける
def wheel(pos):
global red, green, blue
# 2色選択
WheelPos = pos % 255
# 3分割しているので1/3の値を求める
one_third = (WheelPos % 85)
big = one_third * 3
small = 255 - big
# 赤<=>緑
if WheelPos < 85:
red = small
green = big
blue = 0
# 緑<=>青
elif 85 <= WheelPos < 170:
red = 0
green = small
blue = big
# 青<=>赤
else :
red = big
green = 0
blue = small
np.brightness(20)
while True:
for i in range(0, 255):
for j in range(0, 8):
wheel(i + j*255 // 8)
np.set_pixel(j, red, green, blue)
np.show()
time.sleep_ms(1)