1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

電子工作メモ - RainbowLight

Last updated at Posted at 2024-03-21

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)
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?