import board
import neopixel
import time
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.rainbow import Rainbow
from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.animation.sparkle import Sparkle
from adafruit_led_animation.animation.SparklePulse import SparklePulse
from adafruit_led_animation.animation.solid import Solid
from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.animation.colorcycle import ColorCycle
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
from adafruit_led_animation.animation.rainbowchase import RainbowChase
from adafruit_led_animation import helper
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.group import AnimationGroup
from adafruit_led_animation.color import RED, YELLOW, ORANGE, GREEN, TEAL, CYAN, BLUE, PURPLE, MAGENTA, GOLD, PINK, AQUA, JADE, AMBER, OLD_LACE, WHITE, BLACK
# Set the pin and total number of pixels
pixel_pin = board.GP0 # Change this to the correct pin
NUM_STRIPS = 15
NUM_LEDS_PER_STRIP = 30
NUM_LEDS_TOTAL = NUM_STRIPS * NUM_LEDS_PER_STRIP
# Initialize the NeoPixel object for the entire grid of LEDs
pixels = neopixel.NeoPixel(pixel_pin, NUM_LEDS_TOTAL, brightness=0.5, auto_write=False)
# Use PixelMap to treat the strips as vertical columns
pixel_wing_vertical = helper.PixelMap.vertical_lines(
pixels, 30, 15, helper.horizontal_strip_gridmap(30, alternating=False)
)
pixel_wing_horizontal = helper.PixelMap.horizontal_lines(
pixels, 30, 15, helper.horizontal_strip_gridmap(30, alternating=False)
)
# Comet effect running vertically across the strips
comet_h = Comet(pixel_wing_horizontal, speed=0.1, color=PURPLE, tail_length=10, bounce=True)
# Rainbow effect cycling through all strips
# rainbow_v = Rainbow(pixel_map_vertical, speed=0.05, period=2)
comet_v = Comet(pixel_wing_vertical, speed=0.1, color=AMBER, tail_length=20, bounce=True)
chase_h = Chase(pixel_wing_horizontal, speed=0.1, size=5, spacing=5, color=WHITE)
chase_v = Chase(pixel_wing_vertical, speed=0.1, size=5, spacing=5, color=AQUA)
rainbow_chase_v = RainbowChase(pixel_wing_vertical, speed=0.1, size=3, spacing=2)
rainbow_chase_h = RainbowChase(pixel_wing_horizontal, speed=0.1, size=3, spacing=2)
sparkle = Sparkle(pixels, speed=0.05, color=WHITE, num_sparkles=int(NUM_LEDS_TOTAL/2))
sparkle_pulse = SparklePulse(pixels, speed=0.05, period=2, color=TEAL)
solid = Solid(pixels, color=PINK)
blink = Blink(pixels, speed=0.5, color=JADE)
colorcycle = ColorCycle(pixels, 0.5, colors=[RED, YELLOW, ORANGE, GREEN, TEAL, CYAN, BLUE, PURPLE, MAGENTA, GOLD, PINK, AQUA, JADE, AMBER, OLD_LACE, WHITE, BLACK])
chase = Chase(pixels, speed=0.1, color=WHITE, size=3, spacing=6)
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=10, bounce=True)
rainbow_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=int(NUM_LEDS_TOTAL/3))
# Animation sequence, switching between comet and rainbow
animations = AnimationSequence(
comet_h,
comet_v,
chase_h,
chase_v,
rainbow_chase_v,
rainbow_chase_h,
sparkle,
sparkle_pulse,
solid,
blink,
colorcycle,
chase,
comet,
rainbow_comet,
rainbow_sparkle,
advance_interval=5, # Change animations every 5 seconds
)
def divide_into_columns():
"""Function to divide each strip into 3 vertical sections and color them."""
for strip in range(NUM_STRIPS):
start_led = strip * NUM_LEDS_PER_STRIP # Get the starting LED index for this strip
# Divide each strip into three sections (first 10 LEDs, next 10 LEDs, and last 10 LEDs)
for led in range(start_led, start_led + NUM_LEDS_PER_STRIP):
if led < start_led + 10: # First 10 LEDs -> Blue
pixels[led] = BLUE
elif led < start_led + 20: # Next 10 LEDs -> Yellow
pixels[led] = YELLOW
else: # Last 10 LEDs -> Red
pixels[led] = RED
pixels.show()
# Main loop to run the column division
while True:
# divide_into_columns() # Run the animation
animations.animate()