# SPDX-FileCopyrightText: 2025 Pagong # SPDX-License-Identifier: MIT import time import board import neopixel import math ####################### # for Rpi-Pico with 16x16 NeoPixel-Matrix NUM_COLS = 16 NUM_CELLS = 16 NUM_PIXELS = (NUM_COLS * NUM_CELLS) # Update this to match the number of LEDs. SPEED = 0.1 # Increase to slow down the effect. Decrease to speed it up. BRIGHTNESS = 0.1 # A number between 0.0 and 1.0, where 0.0 is off, and 1.0 is max. PIN = board.GP28 # This is the default pin on my RPi-Pico with 16x16 NeoPixel matrix pixels = neopixel.NeoPixel(PIN, NUM_PIXELS, brightness=BRIGHTNESS, auto_write=False) ##################### def lerp(begin, end, t): return begin + t*(end-begin) def hsv2rgb(h, s, v): g = h*6.0 i = math.floor(g) f = g - i p = v * (1.0 - s) q = v * (1.0 - s*f) t = v * (1.0 - s*(1.0-f)) r, g, b = [ (v, t, p), (q, v, p), (p, v, t), (p, q, v), (t, p, v), (v, p, q), ][int(i)%6] return int(r*255), int(g*255), int(b*255) ##################### hue_A = 15 # 15 sat_A = 230 val_min = 120.0 hue_B = 95 # 95 sat_B = 255 val_max = 255.0 palette = [] def breathe(): step = 1.0 # 0.5 delta = (val_max - val_min) / 2.35040238 max_range = 128 for i in range(2*max_range): dV = (math.exp(math.sin(step * i/max_range * math.pi)) - 0.36787944) * delta val = val_min + dV t = (val - val_min) / (val_max - val_min) hue = lerp(hue_A, hue_B, t) sat = lerp(sat_A, sat_B, t) rgb = hsv2rgb(hue/255.0, sat/255.0, val/255.0) #print(i, dV, val, rgb) palette.append(rgb) ##################### pulse = 2.5 breathe() while True: for i in range(256): color = palette[int(pulse*i)&255] pixels.fill(color) pixels.show() time.sleep(SPEED)