#!/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 circle (n1=50, n2=100, n3=200, n4=0) print("Test 1: Basic circle (n1=50, n2=100, n3=200, n4=0)") p.add("circle1", { "pattern": "circle", "brightness": 255, "n1": 50, # Head moves 50 LEDs/second "n2": 100, # Max length 100 LEDs "n3": 200, # Tail moves 200 LEDs/second "n4": 0, # Min length 0 LEDs "colors": [(255, 0, 0)] # Red }) p.select("circle1") run_for(p, wdt, 5000) # Test 2: Slow growth, fast shrink (n1=20, n2=50, n3=100, n4=0) print("Test 2: Slow growth, fast shrink (n1=20, n2=50, n3=100, n4=0)") p.add("circle2", { "pattern": "circle", "n1": 20, "n2": 50, "n3": 100, "n4": 0, "colors": [(0, 255, 0)] # Green }) p.select("circle2") run_for(p, wdt, 5000) # Test 3: Fast growth, slow shrink (n1=100, n2=30, n3=20, n4=0) print("Test 3: Fast growth, slow shrink (n1=100, n2=30, n3=20, n4=0)") p.add("circle3", { "pattern": "circle", "n1": 100, "n2": 30, "n3": 20, "n4": 0, "colors": [(0, 0, 255)] # Blue }) p.select("circle3") run_for(p, wdt, 5000) # Test 4: With minimum length (n1=50, n2=40, n3=100, n4=10) print("Test 4: With minimum length (n1=50, n2=40, n3=100, n4=10)") p.add("circle4", { "pattern": "circle", "n1": 50, "n2": 40, "n3": 100, "n4": 10, "colors": [(255, 255, 0)] # Yellow }) p.select("circle4") run_for(p, wdt, 5000) # Test 5: Very fast (n1=200, n2=20, n3=200, n4=0) print("Test 5: Very fast (n1=200, n2=20, n3=200, n4=0)") p.add("circle5", { "pattern": "circle", "n1": 200, "n2": 20, "n3": 200, "n4": 0, "colors": [(255, 0, 255)] # Magenta }) p.select("circle5") run_for(p, wdt, 3000) # Test 6: Very slow (n1=10, n2=25, n3=10, n4=0) print("Test 6: Very slow (n1=10, n2=25, n3=10, n4=0)") p.add("circle6", { "pattern": "circle", "n1": 10, "n2": 25, "n3": 10, "n4": 0, "colors": [(0, 255, 255)] # Cyan }) p.select("circle6") run_for(p, wdt, 5000) # Cleanup print("Test complete, turning off") p.add("cleanup_off", {"pattern": "off"}) p.select("cleanup_off") run_for(p, wdt, 100) if __name__ == "__main__": main()