# 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.GP16
# The number of NeoPixels
num_pixels = 126
# 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=.5, auto_write=False, pixel_order=ORDER
# )
# def wheel(pos):
# # Input a value 0 to 255 to get a color value.
# # The colours are a transition r - g - b - back to r.
# if pos < 0 or pos > 255:
# r = g = b = 0
# elif pos < 85:
# r = int(pos * 3)
# g = int(255 - pos * 3)
# b = 0
# elif pos < 170:
# pos -= 85
# r = int(255 - pos * 3)
# g = 0
# b = int(pos * 3)
# else:
# pos -= 170
# r = 0
# g = int(pos * 3)
# b = int(255 - pos * 3)
# return (r, g, b) if ORDER in (neopixel.RGB, neopixel.GRB) else (r, g, b, 0)
# def rainbow_cycle(wait):
# for j in range(255):
# for i in range(num_pixels):
# pixel_index = (i * 256 // num_pixels) + j
# pixels[i] = wheel(pixel_index & 255)
# pixels.show()
# time.sleep(wait)
# while True:
# # Comment this line out if you have RGBW/GRBW NeoPixels
# pixels.fill((255, 0, 0))
# # Uncomment this line if you have RGBW/GRBW NeoPixels
# # pixels.fill((255, 0, 0, 0))
# pixels.show()
# time.sleep(1)
# # Comment this line out if you have RGBW/GRBW NeoPixels
# # Uncomment this line if you have RGBW/GRBW NeoPixels
# # pixels.fill((0, 255, 0, 0))
# pixels.show()
# time.sleep(1)
# # Comment this line out if you have RGBW/GRBW NeoPixels
# pixels.fill((0, 0, 255))
# # Uncomment this line if you have RGBW/GRBW NeoPixels
# # pixels.fill((0, 0, 255, 0))
# pixels.show()
# time.sleep(1)
# rainbow_cycle(0.001) # rainbow cycle with 1ms delay per step
# Colors
# Green
AUTO_AIMING_COLOR = (0, 252, 0)
# Purple
ENABLED_COLOR = (119, 3, 252)
# Green
BALANCED_COLOR = (19, 252, 3)
# Red
RED_ALLIANCE_COLOR = (255, 0, 0)
# Blue
BLUE_ALLIANCE_COLOR = (0, 0, 255)
# Yellow
GIMME_CONE_COLOR = (240, 252, 3)
# Purple
GIMME_CUBE_COLOR = (119, 3, 252)
# Black light
ALLIANCE_COLOR = (0,0,0)
pixels = neopixel.NeoPixel(
pixel_pin, num_pixels, brightness=0.5, auto_write=False, pixel_order=ORDER
)
ring1 = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
leftGround1 = [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48 ,49 ,50, 51, 52, 53, 54, 55, 56, 57, 58 ]
rightGround1 = [59, 60,61,62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101]
sponsor1 = [ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125]
n = pixels.n
def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colors are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
r = g = b = 0
elif pos < 85:
r = int(pos * 3)
g = int(255 - pos * 3)
b = 0
elif pos < 170:
pos -= 85
r = int(255 - pos * 3)
g = 0
b = int(pos * 3)
else:
pos -= 170
r = 0
g = int(pos * 3)
b = int(255 - pos * 3)
return (r, g, b) if ORDER in (neopixel.RGB, neopixel.GRB) else (r, g, b, 0)
def rainbow_cycle(start_color):
for i in range(num_pixels):
pixel_index = (i * 256 // num_pixels) + start_color
pixels[i] = wheel(pixel_index & 255)
def color_chase(color1, color2, wait):
for i in range(sponsor1[0],sponsor1[-1],1):
pixels[i] = color1
pixels[i+1] = color1
pixels[i-2] = color2
pixels.show()
for i in sponsor1:
pixels[i] = color2
pixels.show()
for i in range(rightGround1[0],rightGround1[-1],1):
pixels[i] = color1
pixels[i+1] = color1
pixels[i-2] = color2
pixels.show()
for i in rightGround1:
pixels[i] = color2
pixels.show()
for i in range(sponsor1[-1],sponsor1[0],-1):
pixels[i] = color1
pixels[i-1] = color1
pixels[i-2] = color2
print(i)
pixels.show()
for i in sponsor1:
pixels[i] = color2
pixels.show()
for i in range(leftGround1[0],leftGround1[-1],1):
pixels[i] = color1
pixels[i+1] = color1
pixels[i-2] = color2
pixels.show()
for i in leftGround1:
pixels[i] = color2
time.sleep(wait)
def bounce_cycle():
for i in range(4 * n):
pixels[i] = (0, 0, 0)
pixels.show()
time.sleep(1)
def set_alliance_color():
global ALLIANCE_COLOR
if BLUE_ALLIANCE:
ALLIANCE_COLOR = BLUE_ALLIANCE_COLOR
if RED_ALLIANCE:
ALLIANCE_COLOR = RED_ALLIANCE_COLOR
def enabled_cycle():
global ALLIANCE_COLOR
set_alliance_color()
for i in ring1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = ALLIANCE_COLOR
for i in leftGround1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = ALLIANCE_COLOR
for i in rightGround1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = ALLIANCE_COLOR
for i in sponsor1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = ALLIANCE_COLOR
def auto_aiming_cycle():
for i in ring1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = ALLIANCE_COLOR
for i in leftGround1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = ALLIANCE_COLOR
for i in rightGround1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = AUTO_AIMING_COLOR
for i in sponsor1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = AUTO_AIMING_COLOR
def balanced_cycle():
global BALANCED_COLOR
for i in ring1:
# pixels[i].brightness(1.0)
pixels[i] = BALANCED_COLOR
pixels.show()
time.sleep(3)
pixels.fill(ALLIANCE_COLOR)
pixels.show()
time.sleep(3)
def gimme_cube_cycle():
# for i in ring1:
# # pixel_index = (i * 256 // num_pixels)
# pixels[i] = GIMME_CUBE_COLOR
# for i in leftGround1:
# # pixel_index = (i * 256 // num_pixels)
# pixels[i] = GIMME_CUBE_COLOR
# for i in rightGround1:
# # pixel_index = (i * 256 // num_pixels)
# pixels[i] = GIMME_CUBE_COLOR
for i in sponsor1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = GIMME_CUBE_COLOR
def gimme_cone_cycle():
# for i in ring1:
# # pixel_index = (i * 256 // num_pixels)
# pixels[i] = GIMME_CONE_COLOR
# for i in leftGround1:
# # pixel_index = (i * 256 // num_pixels)
# pixels[i] = GIMME_CONE_COLOR
# for i in rightGround1:
# # pixel_index = (i * 256 // num_pixels)
# pixels[i] = GIMME_CONE_COLOR
for i in sponsor1:
# pixel_index = (i * 256 // num_pixels)
pixels[i] = GIMME_CONE_COLOR
ENABLED = True
AUTO_AIMING = False
BALANCED = False
BLUE_ALLIANCE = True
RED_ALLIANCE = False
GIMME_CUBE = False
GIMME_CONE = False
def handle_state():
wheel_start_color = 0
while True:
if ENABLED:
enabled_cycle()
if AUTO_AIMING:
auto_aiming_cycle()
if AUTO_AIMING:
auto_aiming_cycle()
if GIMME_CUBE:
gimme_cube_cycle()
if GIMME_CONE:
gimme_cone_cycle()
if BALANCED:
balanced_cycle()
# bounce_cycle()
color_chase(GIMME_CONE_COLOR, ALLIANCE_COLOR, .05)
else:
rainbow_cycle(wheel_start_color)
wheel_start_color = (wheel_start_color + 1) % 256
pixels.show()
time.sleep(.1)
while True:
handle_state()