import machine
import neopixel
import time
import random
import math
# Set pins
NUM_LEDS =1374 # Adjust for your setup
PIN = 16 # GPIO pin for NeoPixels
np = neopixel.NeoPixel(machine.Pin(PIN), NUM_LEDS)
def turn_led_on(color):
for i in range(len(np)):
np[i] = color
np.write() # Write only once after setting all LEDs
# Colors sorted from light to dark
White = [255, 255, 255]
LightCyan = [224, 255, 255]
LightYellow = [255, 255, 224]
LemonChiffon = [255, 250, 205]
Lavender = [230, 230, 250]
Plum = [221, 160, 221]
LightPink = [255, 182, 193]
LightSalmon = [255, 160, 122]
LightGreen = [144, 238, 144]
PaleGreen = [152, 251, 152]
Gold = [255, 215, 0]
Yellow = [255, 255, 0]
LightGray = [211, 211, 211]
Silver = [192, 192, 192]
BabyBlue = [0, 191, 255]
DeepSkyBlue = [0, 191, 255]
DodgerBlue = [30, 144, 255]
RoyalBlue = [65, 105, 225]
Cyan = [0, 255, 255]
Aqua = [0, 255, 255]
MediumTurquoise = [72, 209, 204]
Turquoise = [64, 224, 208]
DarkTurquoise = [0, 206, 209]
SpringGreen = [0, 255, 127]
MediumSeaGreen = [60, 179, 113]
SeaGreen = [46, 139, 87]
Lime = [50, 205, 50]
Green = [0, 255, 0]
Teal = [0, 128, 128]
DarkGreen = [34, 139, 34]
ForestGreen = [34, 139, 34]
MediumPurple = [147, 112, 219]
Orchid = [218, 112, 214]
DeepPink = [255, 20, 147]
HotPink = [255, 105, 180]
PaleVioletRed = [219, 112, 147]
MediumVioletRed = [199, 21, 133]
DarkOrchid = [153, 50, 204]
DarkViolet = [148, 0, 211]
Purple = [128, 0, 128]
Indigo = [75, 0, 130]
Crimson = [220, 20, 60]
Firebrick = [178, 34, 34]
Tomato = [255, 99, 71]
Coral = [255, 127, 80]
Salmon = [250, 128, 114]
Orange = [255, 165, 0]
Dark_Orange = [255, 140, 0]
Red = [255, 0, 0]
DarkRed = [139, 0, 0]
Navy = [0, 0, 128]
MidnightBlue = [25, 25, 112]
DarkBlue = [0, 0, 139]
MediumBlue = [0, 0, 205]
Blue = [0, 0, 255]
DarkGray = [169, 169, 169]
DimGray = [105, 105, 105]
Black = [0, 0, 0]
Off = [0, 0, 0]
# Expanded color list
color_list = [
White, LightGray, Silver, LightYellow, LemonChiffon, LightCyan, LightPink, LightSalmon, LightGreen,
PaleGreen, LightGreen, LightCyan, BabyBlue, DeepSkyBlue, DodgerBlue, RoyalBlue, Blue, MediumBlue,
DeepPink, HotPink, PaleVioletRed, MediumVioletRed, Orchid, Plum, Lavender, Gold, Yellow,
LightSalmon, Coral, Salmon, Tomato, Orange, Dark_Orange, Lime, SpringGreen, SeaGreen, MediumSeaGreen,
Teal, ForestGreen, Green, DarkGreen, Crimson, Firebrick, DarkRed, Red, DarkOrchid, DarkViolet,
Purple, Indigo, MidnightBlue, Navy, DarkTurquoise, Turquoise, Cyan, Aqua, MediumTurquoise,
MediumPurple, DarkBlue, DarkGray, DimGray, Black, Off
]
def go_thru_color_list():
print("color list")
for color in color_list:
turn_led_on(color)
print(color_list[0])
time.sleep(4)
def fire_effect2(duration=20, delay=0.05):
"""Creates a more realistic fire effect with smooth flickering and upward movement."""
start_time = time.time()
print("fire effect 2")
frame = 0 # Tracks animation progress
while time.time() - start_time < duration:
for i in range(len(np)):
# Create a fire gradient with more red at the bottom and yellow at the top
flicker = int(50 * math.sin((frame / 5) + (i / 3))) # Smooth flickering with sine wave
base_red = 180 + flicker + random.randint(-20, 20) # Fire is mostly red
base_green = max(50, 100 + flicker + random.randint(-30, 30)) # Some green for orange effect
base_blue = 0 # No blue in fire
# Simulate embers (random pixels glowing brighter)
if random.random() > 0.95:
base_red = 255
base_green = 150
np[i] = (min(255, base_red), min(255, base_green), base_blue)
np.write()
time.sleep(delay)
frame += 1 # Progress animation
def generate_fire_palette():
"""Creates a smooth color gradient for fire from deep red to yellow."""
palette = []
for i in range(256):
if i < 85:
palette.append((i * 3, 0, 0)) # Dark red
elif i < 170:
palette.append((255, (i - 85) * 3, 0)) # Orange
else:
palette.append((255, 255, (i - 170) * 3)) # Yellow
return palette
FIRE_PALETTE = generate_fire_palette()
def fire_effect3(duration=10, delay=0.05, cooling=80, sparking=120):
print("fire effect 3")
start_time = time.time()
NUM_LEDS =len(np)
heat = [0] * len(np) # Stores heat levels per LED
while time.time() - start_time < duration:
# Cool down every cell a little bit
for i in range(NUM_LEDS):
heat[i] = max(0, heat[i] - random.randint(0, ((cooling * 10) // NUM_LEDS) + 2))
# Heat diffuses upwards
for i in range(NUM_LEDS - 1, 2, -1):
heat[i] = (heat[i - 1] + heat[i - 2] + heat[i - 3]) // 3
# Randomly ignite new sparks at the bottom
if random.randint(0, 255) < sparking:
y = random.randint(0, min(6, NUM_LEDS - 1)) # Bottom LEDs
heat[y] = min(255, heat[y] + random.randint(160, 255))
# Convert heat to color
for i in range(NUM_LEDS):
color_index = min(255, heat[i])
np[i] = FIRE_PALETTE[color_index]
np.write()
time.sleep(delay)
def fire_effect4(duration=15, delay=0.04, cooling=50, sparking=120, fire_height=8):
"""
Creates an advanced rolling fire effect with realistic movement.
Parameters:
- `duration`: Time in seconds to run the fire effect.
- `delay`: Speed of animation (lower is faster).
- `cooling`: Controls how fast heat cools down (higher = faster).
- `sparking`: Controls how many new sparks ignite at the base.
- `fire_height`: Controls the height of the flames (higher = taller fire).
"""
print("fire effect 4")
start_time = time.time()
NUM_LEDS =len(np)
heat = [0] * NUM_LEDS # Heat level per LED
while time.time() - start_time < duration:
# Step 1: Cool down every cell slightly
for i in range(NUM_LEDS):
heat[i] = max(0, heat[i] - random.randint(0, ((cooling * 10) // NUM_LEDS) + 2))
# Step 2: Heat diffuses upwards (fire rolls upward)
for i in range(NUM_LEDS - 1, fire_height, -1):
heat[i] = (heat[i - 1] + heat[i - 2] + heat[i - 3]) // 3
# Step 3: Randomly ignite new sparks at the bottom
if random.randint(0, 255) < sparking:
y = random.randint(0, fire_height) # Sparks appear in the lower section
heat[y] = min(255, heat[y] + random.randint(160, 255))
# Step 4: Convert heat to color using the fire palette
for i in range(NUM_LEDS):
color_index = min(255, heat[i])
np[i] = FIRE_PALETTE[color_index]
np.write()
time.sleep(delay)
def clear_strip():
"""Turn off all LEDs."""
for i in range(NUM_LEDS):
np[i] = (0, 0, 0)
def bouncing_balls(duration=15):
balls = [
{"pos": 0, "speed": 1, "color": (255, 0, 0), "dir": 1}, # Red ball
{"pos": NUM_LEDS // 3, "speed": 2, "color": (255, 255, 255), "dir": 1}, # white ball
{"pos": (NUM_LEDS // 3) * 2, "speed": 3, "color": (0, 0, 255), "dir": 1}, # Blue ball
{"pos": 0, "speed": 1, "color": (255, 0, 0), "dir": -1}, # Red ball
{"pos": NUM_LEDS // 3, "speed": 2, "color": (255, 255, 255), "dir": -1}, # white ball
{"pos": (NUM_LEDS // 3) * 2, "speed": 3, "color": (0, 0, 255), "dir": -1}, # Blue ball
]
"""Runs bouncing balls animation."""
print("bouncing_balls")
start_time = time.time()
while time.time() - start_time < duration:
clear_strip() # Clear previous frame
for ball in balls:
# Move ball
ball["pos"] += ball["speed"] * ball["dir"]
# Bounce off edges (ensuring it stays within valid range)
if ball["pos"] >= NUM_LEDS - 1:
ball["pos"] = NUM_LEDS - 2 # Prevent going out of range
ball["dir"] *= -1 # Reverse direction
elif ball["pos"] <= 0:
ball["pos"] = 1 # Prevent going out of range
ball["dir"] *= -1 # Reverse direction
# Draw ball at valid position
np[int(ball["pos"])] = ball["color"]
np.write()
time.sleep(0.05) # Adjust speed
def random_balls(duration=15):
balls = [
{
"pos": random.randint(0, NUM_LEDS - 1),
"speed": random.uniform(0.5, 1.5),
"dir": random.choice([-1, 1]),
"color": [random.randint(0, 255) for _ in range(3)]
}
for _ in range(10) # More balls!
]
"""Runs bouncing balls animation."""
print("Bouncing Balls Animation Starting...")
start_time = time.time()
while time.time() - start_time < duration:
clear_strip() # Clear previous frame
for ball in balls:
# Move ball
ball["pos"] += ball["speed"] * ball["dir"]
ball["pos"] = max(0, min(NUM_LEDS - 1, round(ball["pos"])))
# Bounce off edges
if ball["pos"] >= NUM_LEDS - 1 or ball["pos"] <= 0:
ball["dir"] *= -1 # Reverse direction
# Draw ball at valid position
np[int(ball["pos"])] = ball["color"]
np.write()
time.sleep(0.05) # Adjust speed
def techno_wave(duration=10, delay=0.1):
print("techno_wave")
"""Creates a smooth techno wave effect across the LEDs."""
start_time = time.time()
while time.time() - start_time < duration:
for i in range(NUM_LEDS):
color = random.choice(color_list)
np[i] = color
np.write()
time.sleep(delay)
def flashing_lights(duration=10, delay=0.1):
"""Creates flashing lights with random colors at random intervals."""
print("flashing_lights")
start_time = time.time()
while time.time() - start_time < duration:
color = random.choice(color_list)
for i in range(NUM_LEDS):
np[i] = color
np.write()
time.sleep(delay)
clear_strip() # Turn off after flashing
time.sleep(delay)
def techno_blink(duration=10, delay=0.05):
"""Creates a flashing blink effect across the strip."""
print("techno_blink")
start_time = time.time()
while time.time() - start_time < duration:
for i in range(NUM_LEDS):
np[i] = random.choice(color_list)
np.write()
time.sleep(delay)
clear_strip()
time.sleep(delay)
# Rainbow Wave Effect
def rainbow_wave(wait=0.02):
print("rainbow_wave")
for j in range(256):
for i in range(NUM_LEDS):
pixel_index = (i * 256 // NUM_LEDS) + j
np[i] = wheel(pixel_index & 255)
np.write()
time.sleep(wait)
# Color Wipe
def color_wipe(color, wait=0.05):
print("color_wipe")
for color in color_list:
for i in range(NUM_LEDS):
np[i] = color
np.write()
time.sleep(wait)
# Lightning Effect
def lightning(duration=5):
print("lightning")
start_time = time.time()
while time.time() - start_time < duration:
flash_start = random.randint(0, NUM_LEDS - 20)
flash_length = random.randint(5, 20)
for i in range(flash_start, flash_start + flash_length):
if i < NUM_LEDS:
np[i] = (255, 255, 255)
np.write()
time.sleep(random.uniform(0.05, 0.2))
np.fill((0, 0, 0))
np.write()
time.sleep(random.uniform(0.1, 0.5))
# Twinkle Stars
def twinkle_stars(count=10, duration=10):
print("twinkle_stars")
start_time = time.time()
while time.time() - start_time < duration:
np.fill((0, 0, 0))
for _ in range(count):
index = random.randint(0, NUM_LEDS - 1)
np[index] = (255, 255, 255)
np.write()
time.sleep(0.2)
# Comet Effect
def comet(color=(0, 255, 255), tail_length=10, speed=0.05):
print("comet")
for i in range(NUM_LEDS + tail_length):
np.fill((0, 0, 0))
for j in range(tail_length):
if i - j >= 0 and i - j < NUM_LEDS:
brightness = 255 - (j * (255 // tail_length))
np[i - j] = tuple(int(c * (brightness / 255)) for c in color)
np.write()
time.sleep(speed)
# Inferno Wave
def inferno_wave(duration=10, delay=0.05):
print("inferno_wave")
start_time = time.time()
while time.time() - start_time < duration:
for i in range(NUM_LEDS):
red = random.randint(180, 255)
green = random.randint(50, 150)
blue = random.randint(0, 50)
np[i] = (red, green, blue)
np.write()
time.sleep(delay)
# Rainbow Color Wheel
def wheel(pos):
if pos < 85:
return (pos * 3, 255 - pos * 3, 0)
elif pos < 170:
pos -= 85
return (255 - pos * 3, 0, pos * 3)
else:
pos -= 170
return (0, pos * 3, 255 - pos * 3)
def rainbow_cycle(delay=0.02, cycles=5):
print("rainbow cycle")
for _ in range(cycles * 256):
for i in range(NUM_LEDS):
pixel_index = (i * 256 // NUM_LEDS) + _
np[i] = wheel(pixel_index & 255)
np.write()
time.sleep(delay)
def meteor_rain(color=(255, 0, 0), decay=0.75, delay=0.04):
print("meteor_rain")
trail = [0] * NUM_LEDS
for _ in range(NUM_LEDS * 2):
for i in range(NUM_LEDS - 1, 0, -1):
trail[i] = int(trail[i - 1] * decay)
trail[0] = 255
for i in range(NUM_LEDS):
np[i] = (int(color[0] * trail[i] / 255),
int(color[1] * trail[i] / 255),
int(color[2] * trail[i] / 255))
np.write()
time.sleep(delay)
def lightning_strike(duration=5, flashes=5):
print("lightning_strike")
start_time = time.time()
while time.time() - start_time < duration:
for _ in range(flashes):
for i in range(NUM_LEDS):
np[i] = (255, 255, 255)
np.write()
time.sleep(random.uniform(0.05, 0.2))
clear_strip()
time.sleep(random.uniform(0.05, 0.5))
def comet_trail(color=(0, 255, 255), tail=10, delay=0.05):
print("comet_trail")
for i in range(NUM_LEDS + tail):
clear_strip()
for j in range(tail):
if i - j < NUM_LEDS and i - j >= 0:
np[i - j] = tuple(max(0, int(c * (1 - (j / tail)))) for c in color)
np.write()
time.sleep(delay)
def knight_rider2(num_leds=NUM_LEDS, width=20, color=(255, 0, 0), duration=15, delay=0.01):
"""Knight Rider effect with a moving bar of `width` LEDs."""
print("knight rider 2")
start_time = time.time()
pos = 0
direction = 1 # 1 = moving forward, -1 = moving backward
while time.time() - start_time < duration:
# Clear strip
for i in range(num_leds):
np[i] = (0, 0, 0)
# Light up the 10-LED wide segment
for i in range(width):
index = pos + i
if 0 <= index < num_leds:
np[index] = color
np.write()
time.sleep(delay)
# Move the light bar
pos += direction
# Bounce at edges
if pos + width >= num_leds or pos <= 0:
direction *= -1
def hyperspace_jump(duration=3, speed=0.02):
print("hyperspace_jump")
for _ in range(int(duration / speed)):
clear_strip()
for i in range(NUM_LEDS):
np[i] = (255, 255, 255) if random.random() > 0.9 else (0, 0, 0)
np.write()
time.sleep(speed)
def explosion_effect(delay=0.03):
print("explosion_effect")
for i in range(NUM_LEDS // 2):
color = wheel(random.randint(0, 255))
np[i] = color
np[NUM_LEDS - 1 - i] = color
np.write()
time.sleep(delay)
time.sleep(0.5)
clear_strip()
def ocean_wave(delay=0.01, cycles=1):
print("ocean_wave")
for _ in range(cycles * 256):
for i in range(NUM_LEDS):
pixel_index = (i * 256 // NUM_LEDS) + _
np[i] = (0, wheel(pixel_index & 255)[1], 255)
np.write()
time.sleep(delay)
def plasma_wave(duration=15, speed=0.1):
print("plasma_wave")
start_time = time.time()
offset = 0
while time.time() - start_time < duration:
for i in range(NUM_LEDS):
np[i] = wheel((i * 8 + offset) & 255)
np.write()
offset += 5
time.sleep(speed)
def vortex_spin(duration=15, speed=0.05):
print("vortex_spin")
start_time = time.time()
offset = 0
while time.time() - start_time < duration:
for i in range(NUM_LEDS):
np[i] = wheel((i * 16 + offset) & 255)
np.write()
offset += 10
time.sleep(speed)
def electric_pulse(color=(255, 255, 255), duration=10):
print("electric pulse")
start_time = time.time()
while time.time() - start_time < duration:
np.fill(color)
np.write()
time.sleep(random.uniform(0.01, 0.1))
np.fill((0, 0, 0))
np.write()
time.sleep(random.uniform(0.02, 0.15))
def nuclear_core(color=(0, 255, 0), duration=10):
print("nuclear_core")
start_time = time.time()
brightness = 0
fade_in = True
while time.time() - start_time < duration:
np.fill((color[0] * brightness // 255, color[1] * brightness // 255, color[2] * brightness // 255))
np.write()
time.sleep(0.02)
if fade_in:
brightness += 10
if brightness >= 255:
fade_in = False
else:
brightness -= 10
if brightness <= 50:
fade_in = True
def alien_scanner(duration=15, speed=0.02):
print("alien scanner")
start_time = time.time()
offset = 0
while time.time() - start_time < duration:
for i in range(NUM_LEDS):
np[i] = (0, (i * 5 + offset) % 255, (255 - i * 5 - offset) % 255)
np.write()
offset += 5
time.sleep(speed)
def supernova(color=(255, 255, 0), duration=5):
print("super nova")
start_time = time.time()
brightness = 0
fade_in = True
while time.time() - start_time < duration:
np.fill((color[0] * brightness // 255, color[1] * brightness // 255, color[2] * brightness // 255))
np.write()
time.sleep(0.01)
if fade_in:
brightness += 20
if brightness >= 255:
fade_in = False
else:
brightness -= 50
if brightness <= 0:
break
#Run the fire effect
while True:
#turn_led_on(White)
#time.sleep(60)
bouncing_balls(duration=20)
random_balls(duration=20)
knight_rider2(width=10, color=(255, 0, 0), duration=20, delay=0.01)
lightning_strike()
rainbow_wave()
lightning()
twinkle_stars()
comet()
inferno_wave()
techno_blink(duration=10, delay=0.05)
flashing_lights(duration=10, delay=0.1)
techno_wave(duration=10, delay=0.1)
fire_effect2(duration=10)
fire_effect3(duration=15, cooling=90, sparking=150) # More intense fire
fire_effect4(duration=20, cooling=60, sparking=150, fire_height=10) # More intense fire!
bouncing_balls(duration=20)
vortex_spin()
electric_pulse()
nuclear_core()
alien_scanner(duration=15, speed=0.01)
supernova(color=(255, 255, 0), duration=5)
hyperspace_jump(duration=3, speed=0.02)
plasma_wave()
ocean_wave()
rainbow_cycle()
meteor_rain()
comet_trail()
explosion_effect()
hyperspace_jump()
color_wipe((255, 0, 0)) # Red wipe
go_thru_color_list()