# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# Simple test for NeoPixels on Raspberry Pi
import time
import board
import neopixel
# Choose an open pin connected to the Data In of the NeoPixel strip, i.e. board.D18
# NeoPixels must be connected to D10, D12, D18 or D21 to work.
pixel_pin = board.GP17
pixel_pin2 = board.GP16
pixel_pin3 = board.GP18
# The number of NeoPixels
num_pixels = 16
# The order of the pixel colors - RGB or GRB. Some NeoPixels have red and green reversed!
# For RGBW NeoPixels, simply change the ORDER to RGBW or GRBW.
ORDER = neopixel.GRB
pixels = neopixel.NeoPixel(
pixel_pin, num_pixels, brightness=1, auto_write=False, pixel_order=ORDER
)
pixels2 = neopixel.NeoPixel(
pixel_pin2, num_pixels, brightness=1, auto_write=False, pixel_order=ORDER
)
pixels3 = neopixel.NeoPixel(
pixel_pin3, num_pixels, brightness=1, auto_write=False, pixel_order=ORDER
)
#Aqua 102,255,255
#50, 0, 100)); // Purple
#(255, 0, 135)); // hot-pink
#(255, 0, 255)); //magenta
#255, 87, 51)); //orange
CO = 1/num_pixels
YTBR = (254-114)
YTBG = (249-202)
YTBB = (12.9-60)
BTPR = 102 - 50
BTPG = 255 - 0
BTPB = 255 - 100
PTMR = 255 - 255
PTMG = 0 - 0
PTMB = 135 - 255
#Start_R = 255
#Start_G = 0
#Start_B = 135
#Coeff_R = -CO * PTMR
#Coeff_G = -CO * PTMG
#Coeff_B = -CO * PTMB
Start_R_P = 255
Start_G_P = 0
Start_B_P= 135
Coeff_R_P= -CO * PTMR
Coeff_G_P= -CO * PTMG
Coeff_B_P= -CO * PTMB
Start_R_Y = 254
Start_G_Y = 249
Start_B_Y= 13
Coeff_R_Y= -CO * YTBR
Coeff_G_Y= -CO * YTBG
Coeff_B_Y= -CO * YTBB
Start_R_B = 102
Start_G_B = 255
Start_B_B= 255
Coeff_R_B= -CO * BTPR
Coeff_G_B= -CO * BTPG
Coeff_B_B= -CO * BTPB
range_num = 16 #number of LEDs changed before reset cycle
step_time = .05 # rainbow cycle with 1ms delay per step
def wheel(pos):
#Set color wheel
pos = num_pixels - pos;
# set color
r= Start_R + pos*Coeff_R
g= Start_G + pos*Coeff_G
b= Start_B + pos*Coeff_B
return (r, g, b) if ORDER in (neopixel.RGB, neopixel.GRB) else (r, g, b, 0)
def rainbow_cycle(wait):
for j in range(range_num):
for i in range(num_pixels):
#pixel_index = (i * num_pixels*2 / num_pixels) + j
pixel_index = (i * 2) + j
pixels[i] = wheel((pixel_index & num_pixels) - 1)
pixels.show()
time.sleep(wait)
def rainbow_cycle2(wait):
for j in range(range_num):
for i in range(num_pixels):
pixel_index = (i * num_pixels*2 // num_pixels) + j
pixels2[i] = wheel(pixel_index & num_pixels-1)
pixels2.show()
time.sleep(wait)
def wheel2(pos,Start_R,Start_G,Start_B,Coeff_R,Coeff_G,Coeff_B ):
#Set color wheel
pos = num_pixels - pos;
# set color
r= Start_R + pos*Coeff_R
g= Start_G + pos*Coeff_G
b= Start_B + pos*Coeff_B
return (r, g, b) if ORDER in (neopixel.RGB, neopixel.GRB) else (r, g, b, 0)
def rainbow_cycle3(wait):
for j in range(range_num):
for i in range(num_pixels):
#pixel_index = (i * num_pixels*2 // num_pixels) + j
pixel_index = (i * 2 ) + j
pixels3[i] = wheel2(pixel_index & num_pixels-1,Start_R_B,Start_B_B,Start_G_B,Coeff_R_B,Coeff_B_B,Coeff_G_B)
pixels2[i] = wheel2(pixel_index & num_pixels-1,Start_R_P,Start_B_P,Start_G_P,Coeff_R_P,Coeff_B_P,Coeff_G_P)
pixels[i] = wheel2(pixel_index & num_pixels-1,Start_R_Y,Start_B_Y,Start_G_Y,Coeff_R_Y,Coeff_B_Y,Coeff_G_Y)
pixels3.show()
pixels2.show()
pixels.show()
time.sleep(wait)# use step ime value to hold position
while True:
#rainbow_cycle(step_time);
#rainbow_cycle2(step_time); # rainbow cycle with 1ms delay per step
rainbow_cycle3(step_time)