""" On-device test for the double_circle pattern using mpremote. Usage (from pico/ dir or project root with adjusted paths): mpremote connect cp src/*.py : mpremote connect cp src/patterns/*.py :patterns mpremote connect cp lib/*.py : mpremote connect cp test/test_double_circle.py : mpremote connect run test_double_circle.py This script: - Instantiates Presets - Creates a few in-memory 'double_circle' presets with different centers, widths, and colors - Selects each one so you can visually confirm the symmetric bands and color gradients """ from presets import Presets, Preset def make_double_circle_preset( name, center, half_width, colors, direction=0, step_size=1, brightness=255 ): """ Helper to build a Preset for the 'double_circle' pattern. center: logical index (0-based, on reference strip 0) half_width: number of LEDs each side of center colors: [color1, color2] where each color is (r,g,b) """ cs = list(colors)[:2] while len(cs) < 2: cs.append((0, 0, 0)) data = { "p": "double_circle", "c": cs, "b": brightness, "n1": center, "n2": half_width, "n3": direction, "n4": step_size, } return name, Preset(data) def show_and_wait(presets, name, preset_obj, wait_ms): """Select a static double_circle preset and hold it for wait_ms.""" presets.presets[name] = preset_obj presets.select(name) # DoubleCircle draws immediately in run(), then just yields; one tick is enough. presets.tick() import utime start = utime.ticks_ms() while utime.ticks_diff(utime.ticks_ms(), start) < wait_ms: presets.tick() def main(): presets = Presets() presets.load() num_leds = presets.strip_length(0) if num_leds <= 0: print("No strips; aborting double_circle test.") return print("Starting double_circle pattern test...") quarter = num_leds // 4 half = num_leds // 2 dc_presets = [] # 1. Center at top (0), moderate width, color1 at center (n3=0) dc_presets.append( make_double_circle_preset( "dc_top_red_to_blue", center=0, half_width=quarter, colors=[(255, 0, 0), (0, 0, 255)], direction=0, ) ) # 2. Center at bottom (half), narrow band, color1 at endpoints (n3=1) dc_presets.append( make_double_circle_preset( "dc_bottom_green_to_purple", center=half, half_width=quarter // 2, colors=[(0, 255, 0), (128, 0, 128)], direction=1, ) ) # 3. Center at quarter, wide band, both directions for comparison dc_presets.append( make_double_circle_preset( "dc_quarter_white_to_cyan_inward", center=quarter, half_width=half, colors=[(255, 255, 255), (0, 255, 255)], direction=0, ) ) dc_presets.append( make_double_circle_preset( "dc_quarter_white_to_cyan_outward", center=quarter, half_width=half, colors=[(255, 255, 255), (0, 255, 255)], direction=1, ) ) # 4. Explicit test: n1 = 50, n2 = 40 (half of 80) inward dc_presets.append( make_double_circle_preset( "dc_n1_50_n2_40_inward", center=50, half_width=40, colors=[(255, 100, 0), (0, 0, 0)], direction=0, ) ) # 5. Explicit test: n1 = num_leds//2, n2 = num_leds//4 outward, stepping as fast as possible center_half = num_leds // 2 radius_quarter = max(1, num_leds // 4) dc_presets.append( make_double_circle_preset( "dc_n1_half_n2_quarter_outward", center=center_half, half_width=radius_quarter, colors=[(0, 150, 255), (0, 0, 0)], direction=1, step_size=radius_quarter, # jump to full radius in one step ) ) # Show each for ~4 seconds for name, preset_obj in dc_presets: print("Showing double_circle preset:", name) show_and_wait(presets, name, preset_obj, wait_ms=4000) print("Double_circle pattern test finished. Turning off LEDs.") presets.select("off") presets.tick() if __name__ == "__main__": main()