import machine, neopixel, time
import urandom
# Setup
width = 16 # width of LED array
height = 16 # height of LED array
n = width * height # number of LEDs
pin = 2 # pin connected to the LEDs
# Create NeoPixel object on GPIO16, controlling n LEDs
np = neopixel.NeoPixel(machine.Pin(pin), n)
# Themes: 'name': ([color_ranges], delay_time, brightness, pulse)
themes = {
'fire': ([(128, 255), (0, 0), (0, 0)], 10, 0.8, True),
'ocean': ([(0, 0), (0, 128), (128, 255)], 20, 0.7, False),
'October': ([(128, 255), (64, 128), (0, 0)], 30, 0.6, False),
'holidays': ([(0, 128), (128, 255), (0, 128)], 40, 1.0, True),
'patriotism': ([(0, 255), (0, 255), (0, 255)], 50, 0.9, False),
'romance': ([(255, 255), (105, 105), (180, 180)], 60, 0.5, True),
'Christmas': ([(0, 255), (0, 128), (0, 0)], 50, 1.0, True),
'January': ([(0, 0), (0, 0), (128, 255)], 60, 0.7, False),
'Halloween': ([(128, 255), (0, 0), (0, 0)], 70, 0.8, True),
'Easter': ([(128, 255), (0, 255), (128, 255)], 80, 0.9, False),
'StPatricks': ([(0, 0), (128, 255), (0, 0)], 70, 0.8, True),
'Valentines': ([(255, 0), (105, 105), (180, 180)], 60, 0.7, False),
}
def theme_cycle(theme):
color_ranges, delay_time, brightness, pulse = themes[theme]
color_array = [(urandom.randint(color_ranges[i][0], color_ranges[i][1]) for i in range(3)) for _ in range(n)]
pulse_direction = 1 # Controls the direction of the pulsing effect
for _ in range(3 * 256):
for y in range(height):
for x in range(width):
# Calculate the adjusted index for zig-zag pattern
idx = y * width + (x if y % 2 == 0 else width - 1 - x)
r, g, b = color_array[idx]
# Increase or decrease the color value to create a dynamic effect
r = (r + urandom.randint(-2, 2)) % 256
g = (g + urandom.randint(-2, 2)) % 256
b = (b + urandom.randint(-2, 2)) % 256
# Keep color within theme range
r = min(max(r, color_ranges[0][0]), color_ranges[0][1])
g = min(max(g, color_ranges[1][0]), color_ranges[1][1])
b = min(max(b, color_ranges[2][0]), color_ranges[2][1])
# Apply brightness and pulsing effect
if pulse:
brightness += 0.01 * pulse_direction
if brightness > 1 or brightness < 0.5:
pulse_direction *= -1 # Reverse direction when min/max is reached
r = int(r * brightness)
g = int(g * brightness)
b = int(b * brightness)
color_array[idx] = (r, g, b)
np[idx] = color_array[idx]
np.write()
time.sleep_ms(delay_time)
while True:
for theme in themes.keys():
theme_cycle(theme)