"""16x16 rainbow wave animation.""" from machine import Pin import neopixel import time from panel16_utils import PANEL_H, PANEL_W, clamp8, xy_to_index np = neopixel.NeoPixel(Pin(4), PANEL_W * PANEL_H) def wheel(pos: int) -> tuple[int, int, int]: pos = 255 - (pos & 255) if pos < 85: return (clamp8(255 - pos * 3), 0, clamp8(pos * 3)) if pos < 170: pos -= 85 return (0, clamp8(pos * 3), clamp8(255 - pos * 3)) pos -= 170 return (clamp8(pos * 3), clamp8(255 - pos * 3), 0) for frame in range(240): for y in range(PANEL_H): for x in range(PANEL_W): color_pos = ((x * 10) + (y * 6) + frame * 5) & 255 np[xy_to_index(x, y)] = wheel(color_pos) np.write() time.sleep(0.04) np.fill((0, 0, 0)) np.write()