#!/usr/bin/env python3 import utime from machine import WDT from settings import Settings from patterns import Patterns def run_for(p, wdt, ms): """Helper: run current pattern for given ms using tick().""" start = utime.ticks_ms() while utime.ticks_diff(utime.ticks_ms(), start) < ms: wdt.feed() p.tick() utime.sleep_ms(10) def main(): s = Settings() pin = s.get("led_pin", 10) num = s.get("num_leds", 30) p = Patterns(pin=pin, num_leds=num) wdt = WDT(timeout=10000) # Test 1: Basic chase (n1=5, n2=5, n3=1, n4=1) print("Test 1: Basic chase (n1=5, n2=5, n3=1, n4=1)") p.edit("chase1", { "pattern": "chase", "brightness": 255, "delay": 200, "n1": 5, "n2": 5, "n3": 1, "n4": 1, "colors": [(255, 0, 0), (0, 255, 0)] }) p.select("chase1") run_for(p, wdt, 3000) # Test 2: Forward and backward (n3=2, n4=-1) print("Test 2: Forward and backward (n3=2, n4=-1)") p.edit("chase2", { "pattern": "chase", "n1": 3, "n2": 3, "n3": 2, "n4": -1, "delay": 150, "colors": [(0, 0, 255), (255, 255, 0)] }) p.select("chase2") run_for(p, wdt, 3000) # Test 3: Large segments (n1=10, n2=5) print("Test 3: Large segments (n1=10, n2=5, n3=3, n4=3)") p.edit("chase3", { "pattern": "chase", "n1": 10, "n2": 5, "n3": 3, "n4": 3, "delay": 200, "colors": [(255, 128, 0), (128, 0, 255)] }) p.select("chase3") run_for(p, wdt, 3000) # Test 4: Fast movement (n3=5, n4=5) print("Test 4: Fast movement (n3=5, n4=5)") p.edit("chase4", { "pattern": "chase", "n1": 4, "n2": 4, "n3": 5, "n4": 5, "delay": 100, "colors": [(255, 0, 255), (0, 255, 255)] }) p.select("chase4") run_for(p, wdt, 2000) # Test 5: Backward movement (n3=-2, n4=-2) print("Test 5: Backward movement (n3=-2, n4=-2)") p.edit("chase5", { "pattern": "chase", "n1": 6, "n2": 4, "n3": -2, "n4": -2, "delay": 200, "colors": [(255, 255, 255), (0, 0, 0)] }) p.select("chase5") run_for(p, wdt, 3000) # Test 6: Alternating forward/backward (n3=3, n4=-2) print("Test 6: Alternating forward/backward (n3=3, n4=-2)") p.edit("chase6", { "pattern": "chase", "n1": 5, "n2": 5, "n3": 3, "n4": -2, "delay": 250, "colors": [(255, 0, 0), (0, 255, 0)] }) p.select("chase6") run_for(p, wdt, 4000) # Test 7: Manual mode - advance one step per beat print("Test 7: Manual mode chase (auto=False, n3=2, n4=1)") p.edit("chase_manual", { "pattern": "chase", "n1": 4, "n2": 4, "n3": 2, "n4": 1, "delay": 200, "colors": [(255, 255, 0), (0, 255, 255)], "auto": False }) p.step = 0 # Reset step counter print(" Advancing pattern with 10 beats (select + tick)...") for i in range(10): p.select("chase_manual") # Simulate beat - restarts generator p.tick() # Advance one step utime.sleep_ms(500) # Pause to see the pattern wdt.feed() print(f" Beat {i+1}: step={p.step}") # Test 8: Verify step increments correctly in manual mode print("Test 8: Verify step increments (auto=False)") p.edit("chase_manual2", { "pattern": "chase", "n1": 3, "n2": 3, "n3": 1, "n4": 1, "auto": False }) p.step = 0 initial_step = p.step p.select("chase_manual2") p.tick() final_step = p.step print(f" Step updated from {initial_step} to {final_step} (expected: 1)") if final_step == 1: print(" ✓ Step increment working correctly") else: print(f" ✗ Step increment mismatch! Expected 1, got {final_step}") # Cleanup print("Test complete, turning off") p.edit("cleanup_off", {"pattern": "off"}) p.select("cleanup_off") run_for(p, wdt, 100) if __name__ == "__main__": main()