import neopixel
import time
from machine import Pin
# Configuration
LED_COUNT = 8
DATA_PIN = 22
FRC_BLUE = (0, 102, 178)
FRC_RED = (236, 34, 41)
COLOR = FRC_RED
# Initialize strip
pin = Pin(DATA_PIN, Pin.OUT)
strip = neopixel.NeoPixel(pin, LED_COUNT)
def shift_on(steps=32, duration_ms=500):
"""
Fade the whole strip from black to COLOR.
"""
delay = duration_ms / steps / 1000
for step in range(steps + 1):
# Calculate brightness ratio (0.0 to 1.0)
ratio = step / steps
color = tuple(int(c * ratio) for c in COLOR)
strip.fill(color)
strip.write()
time.sleep(delay)
def shift_off(steps=32, duration_ms=500):
"""
Fade the whole strip from COLOR to black.
"""
delay = duration_ms / steps / 1000
for step in range(steps, -1, -1):
ratio = step / steps
color = tuple(int(c * ratio) for c in COLOR)
strip.fill(color)
strip.write()
time.sleep(delay)
def pulse(iterations=3):
"""
Performs the pulse effect a set number of times.
"""
for _ in range(iterations):
shift_off()
shift_on()
# Run the effect
try:
strip.fill((100,180,100))
strip.write()
except KeyboardInterrupt:
# Clear pixels on exit
strip.fill((0, 0, 0))
strip.write()