69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
#!/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: Simple two-color transition
|
|
print("Test 1: Two-color transition (red <-> blue, delay=1000)")
|
|
p.set_param("br", 255)
|
|
p.set_param("dl", 1000) # transition duration
|
|
p.set_param("cl", [(255, 0, 0), (0, 0, 255)])
|
|
p.set_param("auto", True)
|
|
p.select("transition")
|
|
run_for(p, wdt, 6000)
|
|
|
|
# Test 2: Multi-color transition
|
|
print("Test 2: Multi-color transition (red -> green -> blue -> white)")
|
|
p.set_param("dl", 800)
|
|
p.set_param("cl", [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 255)])
|
|
p.set_param("auto", True)
|
|
p.select("transition")
|
|
run_for(p, wdt, 8000)
|
|
|
|
# Test 3: One-shot transition (auto=False)
|
|
print("Test 3: One-shot transition (auto=False)")
|
|
p.set_param("dl", 1000)
|
|
p.set_param("cl", [(255, 0, 0), (0, 255, 0)])
|
|
p.set_param("auto", False)
|
|
p.select("transition")
|
|
# Run long enough for a single transition step
|
|
run_for(p, wdt, 2000)
|
|
|
|
# Test 4: Single-color behavior (should just stay on)
|
|
print("Test 4: Single-color transition (should hold color)")
|
|
p.set_param("cl", [(0, 0, 255)])
|
|
p.set_param("dl", 500)
|
|
p.set_param("auto", True)
|
|
p.select("transition")
|
|
run_for(p, wdt, 3000)
|
|
|
|
# Cleanup
|
|
print("Test complete, turning off")
|
|
p.select("off")
|
|
run_for(p, wdt, 200)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
|