Initial commit
This commit is contained in:
123
test/patterns/rainbow.py
Normal file
123
test/patterns/rainbow.py
Normal file
@@ -0,0 +1,123 @@
|
||||
#!/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 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)
|
||||
p.select("rainbow")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 2: Fast rainbow
|
||||
print("Test 2: Fast rainbow (low delay, n1=1)")
|
||||
p.set_param("dl", 50)
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 3: Slow rainbow
|
||||
print("Test 3: Slow rainbow (high delay, n1=1)")
|
||||
p.set_param("dl", 500)
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
run_for(p, wdt, 3000)
|
||||
|
||||
# Test 4: Low brightness rainbow
|
||||
print("Test 4: Low brightness rainbow (n1=1)")
|
||||
p.set_param("br", 64)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 5: Single-step rainbow (auto=False)
|
||||
print("Test 5: Single-step rainbow (auto=False, n1=1)")
|
||||
p.set_param("br", 255)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", False)
|
||||
p.step = 0
|
||||
for i in range(10):
|
||||
p.select("rainbow")
|
||||
# One tick advances the generator one frame when auto=False
|
||||
p.tick()
|
||||
utime.sleep_ms(100)
|
||||
wdt.feed()
|
||||
|
||||
# Test 6: Verify step updates correctly
|
||||
print("Test 6: Verify step updates (auto=False, n1=1)")
|
||||
p.set_param("n1", 1)
|
||||
p.set_param("auto", False)
|
||||
initial_step = p.step
|
||||
p.select("rainbow")
|
||||
p.tick()
|
||||
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.set_param("br", 255)
|
||||
p.set_param("dl", 100)
|
||||
p.set_param("n1", 5)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 8: Very fast step increment (n1=10)
|
||||
print("Test 8: Very fast rainbow (n1=10, auto=True)")
|
||||
p.set_param("n1", 10)
|
||||
p.set_param("auto", True)
|
||||
p.select("rainbow")
|
||||
run_for(p, wdt, 2000)
|
||||
|
||||
# Test 9: Verify n1 controls step increment (auto=False)
|
||||
print("Test 9: Verify n1 step increment (auto=False, n1=5)")
|
||||
p.set_param("n1", 5)
|
||||
p.set_param("auto", False)
|
||||
p.step = 0
|
||||
initial_step = p.step
|
||||
p.select("rainbow")
|
||||
p.tick()
|
||||
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.select("off")
|
||||
run_for(p, wdt, 100)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user