Initial commit
This commit is contained in:
79
test/patterns/pulse.py
Normal file
79
test/patterns/pulse.py
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/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 single-color pulse
|
||||
print("Test 1: Single-color pulse (attack=500, hold=500, decay=500, delay=500)")
|
||||
p.set_param("br", 255)
|
||||
p.set_param("cl", [(255, 0, 0)]) # Red
|
||||
p.set_param("n1", 500) # attack ms
|
||||
p.set_param("n2", 500) # hold ms
|
||||
p.set_param("n3", 500) # decay ms
|
||||
p.set_param("dl", 500) # delay ms between pulses
|
||||
p.set_param("auto", True)
|
||||
p.select("pulse")
|
||||
run_for(p, wdt, 5000)
|
||||
|
||||
# Test 2: Faster pulse
|
||||
print("Test 2: Fast pulse (attack=100, hold=100, decay=100, delay=100)")
|
||||
p.set_param("n1", 100)
|
||||
p.set_param("n2", 100)
|
||||
p.set_param("n3", 100)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("cl", [(0, 255, 0)]) # Green
|
||||
p.select("pulse")
|
||||
run_for(p, wdt, 4000)
|
||||
|
||||
# Test 3: Multi-color pulse cycle
|
||||
print("Test 3: Multi-color pulse (red -> green -> blue)")
|
||||
p.set_param("n1", 300)
|
||||
p.set_param("n2", 300)
|
||||
p.set_param("n3", 300)
|
||||
p.set_param("dl", 200)
|
||||
p.set_param("cl", [(255, 0, 0), (0, 255, 0), (0, 0, 255)])
|
||||
p.set_param("auto", True)
|
||||
p.select("pulse")
|
||||
run_for(p, wdt, 6000)
|
||||
|
||||
# Test 4: One-shot pulse (auto=False)
|
||||
print("Test 4: Single pulse, auto=False")
|
||||
p.set_param("n1", 400)
|
||||
p.set_param("n2", 0)
|
||||
p.set_param("n3", 400)
|
||||
p.set_param("dl", 0)
|
||||
p.set_param("cl", [(255, 255, 255)])
|
||||
p.set_param("auto", False)
|
||||
p.select("pulse")
|
||||
# Run long enough to allow one full pulse cycle
|
||||
run_for(p, wdt, 1500)
|
||||
|
||||
# Cleanup
|
||||
print("Test complete, turning off")
|
||||
p.select("off")
|
||||
run_for(p, wdt, 200)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user