import machine import neopixel import time Configuration NUMPIXELS = 30 # Number of…
- User
import machine import neopixel import time
Configuration
NUM_PIXELS = 30 # Number of pixels in the NeoPixel strip PIN_NUM = 2 # GPIO pin connected to the NeoPixel strip METEOR_SIZE = 5 # Number of LEDs in a meteor METEOR_TRAIL_DECAY = 100 # Trail decay rate SPEED_DELAY = 25 # Speed of the meteor
Initialize the NeoPixel strip
np = neopixel.NeoPixel(machine.Pin(PIN_NUM), NUM_PIXELS)
Function to set color of pixel safely
def set_pixel_color(i, r, g, b): if i >= 0 and i < NUM_PIXELS: np[i] = (r, g, b)
Function to fade all pixels
def fade_to_black(fade_value): for i in range(NUM_PIXELS): r, g, b = np[i] r = 0 if r <= 10 else r - (r * fade_value // 256) g = 0 if g <= 10 else g - (g * fade_value // 256) b = 0 if b <= 10 else b - (b * fade_value // 256) np[i] = (r, g, b)
Main meteor effect function
def meteor_rain(red, green, blue): for i in range(NUM_PIXELS * 2): # Fade to black fade_to_black(METEOR_TRAIL_DECAY)
# Draw meteor for j in range(METEOR_SIZE): if (i - j < NUM_PIXELS) and (i - j >= 0): set_pixel_color(i - j, red, green, blue) np.write() time.sleep_ms(SPEED_DELAY)Main loop
while True: meteor_rain(255, 0, 0) # Red meteor meteor_rain(0, 255, 0) # Green meteor meteor_rain(0, 0, 255) # Blue meteor
combine with this script
def set_neopixel_color_uv(uv_intensity): """Set NeoPixel colors for UV indicators based on UV intensity.""" if uv_intensity is None: color = (0, 0, 0) elif uv_intensity > 0.4: color = (255, 0, 0) elif uv_intensity > 0.25: color = (255, 255, 0) else: color = (255, 0, 255)
for i in UV_LED_RANGE: np[i] = color np.write() - Assistant