168 lines
5.1 KiB
Python
168 lines
5.1 KiB
Python
#!/usr/bin/env python3
|
|
import uasyncio as asyncio
|
|
import utime
|
|
from machine import WDT
|
|
from settings import Settings
|
|
from patterns import Patterns
|
|
|
|
|
|
async 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 rainbow with auto=True (continuous)
|
|
print("Test 1: Basic rainbow (auto=True, n1=1)")
|
|
p.set_param("br", 255)
|
|
p.set_param("dl", 100) # Delay affects animation speed
|
|
p.set_param("n1", 1) # Step increment of 1
|
|
p.set_param("auto", True) # Run continuously
|
|
p.select("rainbow")
|
|
task = asyncio.create_task(p.run())
|
|
start = utime.ticks_ms()
|
|
# Run for 3 seconds to see rainbow animation
|
|
while utime.ticks_diff(utime.ticks_ms(), start) < 3000:
|
|
wdt.feed()
|
|
await asyncio.sleep_ms(10)
|
|
await p.stop()
|
|
await task
|
|
|
|
# Test 2: Fast rainbow
|
|
print("Test 2: Fast rainbow (low delay, n1=1)")
|
|
p.stopped = False
|
|
p.set_param("dl", 50) # Faster animation
|
|
p.set_param("n1", 1)
|
|
p.set_param("auto", True)
|
|
p.select("rainbow")
|
|
task = asyncio.create_task(p.run())
|
|
start = utime.ticks_ms()
|
|
while utime.ticks_diff(utime.ticks_ms(), start) < 2000:
|
|
wdt.feed()
|
|
await asyncio.sleep_ms(10)
|
|
await p.stop()
|
|
await task
|
|
|
|
# Test 3: Slow rainbow
|
|
print("Test 3: Slow rainbow (high delay, n1=1)")
|
|
p.stopped = False
|
|
p.set_param("dl", 500) # Slower animation
|
|
p.set_param("n1", 1)
|
|
p.set_param("auto", True)
|
|
p.select("rainbow")
|
|
task = asyncio.create_task(p.run())
|
|
start = utime.ticks_ms()
|
|
while utime.ticks_diff(utime.ticks_ms(), start) < 3000:
|
|
wdt.feed()
|
|
await asyncio.sleep_ms(10)
|
|
await p.stop()
|
|
await task
|
|
|
|
# Test 4: Low brightness rainbow
|
|
print("Test 4: Low brightness rainbow (n1=1)")
|
|
p.stopped = False
|
|
p.set_param("br", 64) # Low brightness
|
|
p.set_param("dl", 100)
|
|
p.set_param("n1", 1)
|
|
p.set_param("auto", True)
|
|
p.select("rainbow")
|
|
task = asyncio.create_task(p.run())
|
|
start = utime.ticks_ms()
|
|
while utime.ticks_diff(utime.ticks_ms(), start) < 2000:
|
|
wdt.feed()
|
|
await asyncio.sleep_ms(10)
|
|
await p.stop()
|
|
await task
|
|
|
|
# Test 5: Single-step rainbow (auto=False)
|
|
print("Test 5: Single-step rainbow (auto=False, n1=1)")
|
|
p.stopped = False
|
|
p.set_param("br", 255)
|
|
p.set_param("dl", 100)
|
|
p.set_param("n1", 1)
|
|
p.set_param("auto", False) # Run once per call
|
|
p.set_param("step", 0) # Reset step
|
|
p.select("rainbow")
|
|
|
|
# Call rainbow multiple times to see step progression
|
|
for i in range(10):
|
|
task = asyncio.create_task(p.run())
|
|
await task
|
|
await asyncio.sleep_ms(100) # Small delay between steps
|
|
wdt.feed()
|
|
|
|
# Test 6: Verify step updates correctly
|
|
print("Test 6: Verify step updates (auto=False, n1=1)")
|
|
p.stopped = False
|
|
p.set_param("n1", 1)
|
|
initial_step = p.step
|
|
p.select("rainbow")
|
|
task = asyncio.create_task(p.run())
|
|
await task
|
|
final_step = p.step
|
|
print(f"Step updated from {initial_step} to {final_step} (expected increment: 1)")
|
|
|
|
# Test 7: Fast step increment (n1=5)
|
|
print("Test 7: Fast rainbow (n1=5, auto=True)")
|
|
p.stopped = False
|
|
p.set_param("br", 255)
|
|
p.set_param("dl", 100)
|
|
p.set_param("n1", 5) # Step increment of 5 (5x faster)
|
|
p.set_param("auto", True)
|
|
p.select("rainbow")
|
|
task = asyncio.create_task(p.run())
|
|
start = utime.ticks_ms()
|
|
while utime.ticks_diff(utime.ticks_ms(), start) < 2000:
|
|
wdt.feed()
|
|
await asyncio.sleep_ms(10)
|
|
await p.stop()
|
|
await task
|
|
|
|
# Test 8: Very fast step increment (n1=10)
|
|
print("Test 8: Very fast rainbow (n1=10, auto=True)")
|
|
p.stopped = False
|
|
p.set_param("n1", 10) # Step increment of 10 (10x faster)
|
|
p.set_param("auto", True)
|
|
p.select("rainbow")
|
|
task = asyncio.create_task(p.run())
|
|
start = utime.ticks_ms()
|
|
while utime.ticks_diff(utime.ticks_ms(), start) < 2000:
|
|
wdt.feed()
|
|
await asyncio.sleep_ms(10)
|
|
await p.stop()
|
|
await task
|
|
|
|
# Test 9: Verify n1 controls step increment (auto=False)
|
|
print("Test 9: Verify n1 step increment (auto=False, n1=5)")
|
|
p.stopped = False
|
|
p.set_param("n1", 5) # Step increment of 5
|
|
p.set_param("auto", False)
|
|
p.set_param("step", 0) # Reset step
|
|
initial_step = p.step
|
|
p.select("rainbow")
|
|
task = asyncio.create_task(p.run())
|
|
await task
|
|
final_step = p.step
|
|
expected_step = (initial_step + 5) % 256
|
|
print(f"Step updated from {initial_step} to {final_step} (expected: {expected_step})")
|
|
if final_step == expected_step:
|
|
print("✓ n1 step increment working correctly")
|
|
else:
|
|
print(f"✗ Step increment mismatch! Expected {expected_step}, got {final_step}")
|
|
|
|
# Cleanup
|
|
print("Test complete, turning off")
|
|
p.stopped = False
|
|
p.select("off")
|
|
task = asyncio.create_task(p.run())
|
|
await asyncio.sleep_ms(100)
|
|
await p.stop()
|
|
await task
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
|