#!/usr/bin/env python3 """ Test script for rainbow pattern Run with: mpremote run test/rainbow.py """ import patterns import utime from settings import Settings from machine import WDT def run_test_case(p, test_name, duration_ms=5000): """Run a test case for specified duration""" print(f"\n--- {test_name} ---") print(f"Parameters: n1={p.n1} nodes, delay={p.delay}ms cycle time, brightness={p.brightness}") print(f"Running for {duration_ms//1000} seconds...") # Initialize watchdog timer wdt = WDT(timeout=10000) wdt.feed() # Start pattern p.select("rb") # Run for specified duration start_time = utime.ticks_ms() while utime.ticks_diff(utime.ticks_ms(), start_time) < duration_ms: wdt.feed() utime.sleep_ms(100) # Stop pattern p.run = False print(f"{test_name} completed") # Brief pause between tests utime.sleep_ms(500) def test_rainbow(): print("Testing rainbow pattern with multiple configurations...") # Load settings settings = Settings() # Initialize patterns using settings p = patterns.Patterns( pin=settings["led_pin"], num_leds=settings["num_leds"], brightness=255, # Full brightness delay=1000 # Base cycle time ) print(f"LED Pin: {settings['led_pin']}") print(f"LEDs: {settings['num_leds']}") print(f"Base Brightness: {p.brightness}") # Test Case 1: Single node rainbow (full spectrum) p.n1 = 1 # 1 node (full spectrum) p.delay = 3000 # 3 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 1: Single node (full spectrum)", 12000) # Test Case 2: Two node rainbow (red/green) p.n1 = 2 # 2 nodes p.delay = 2000 # 2 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 2: Two nodes (red/green)", 10000) # Test Case 3: Three node rainbow (RGB) p.n1 = 3 # 3 nodes p.delay = 1500 # 1.5 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 3: Three nodes (RGB)", 9000) # Test Case 4: Four node rainbow (RYGB) p.n1 = 4 # 4 nodes p.delay = 1000 # 1 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 4: Four nodes (RYGB)", 8000) # Test Case 5: Six node rainbow (ROYGBP) p.n1 = 6 # 6 nodes p.delay = 800 # 0.8 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 5: Six nodes (ROYGBP)", 8000) # Test Case 6: Eight node rainbow p.n1 = 8 # 8 nodes p.delay = 600 # 0.6 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 6: Eight nodes", 6000) # Test Case 7: Twelve node rainbow (fine gradation) p.n1 = 12 # 12 nodes p.delay = 400 # 0.4 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 7: Twelve nodes (fine gradation)", 6000) # Test Case 8: Many nodes, slow cycle p.n1 = 20 # 20 nodes p.delay = 2000 # 2 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 8: Many nodes, slow cycle", 10000) # Test Case 9: One second cycle p.n1 = 5 # 5 nodes p.delay = 1000 # 1 second cycle p.brightness = 255 # Full brightness run_test_case(p, "Test 9: One second cycle (5 nodes)", 6000) print("\n=== All tests completed ===") # Turn off LEDs p.off() print("LEDs turned off") if __name__ == "__main__": test_rainbow()