Refactor rainbow pattern to travel along the length of LED strip
- Modified rainbow() to distribute colors along the physical length - Each LED gets a different hue based on its position - n1 parameter controls how many times the rainbow cycles (nodes) - Split rainbow tests into test/rainbow/ directory with 9 numbered test files - Each test runs forever until interrupted - Added main.py to run all tests in sequence repeatedly
This commit is contained in:
100
test/rainbow/main.py
Normal file
100
test/rainbow/main.py
Normal file
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Rainbow test suite - runs all tests in sequence forever
|
||||
Run with: mpremote run test/rainbow/main.py
|
||||
"""
|
||||
|
||||
import patterns
|
||||
import utime
|
||||
from settings import Settings
|
||||
from machine import WDT
|
||||
|
||||
def run_test_case(p, test_name, n1, delay, brightness, duration_ms=6000):
|
||||
"""Run a test case for specified duration"""
|
||||
print(f"\n--- {test_name} ---")
|
||||
print(f"Parameters: n1={n1} nodes, delay={delay}ms cycle time, brightness={brightness}")
|
||||
|
||||
# Configure parameters
|
||||
p.n1 = n1
|
||||
p.delay = delay
|
||||
p.brightness = brightness
|
||||
|
||||
# Restart the pattern with new parameters
|
||||
p.run = False
|
||||
while p.running:
|
||||
utime.sleep_ms(1)
|
||||
|
||||
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_suite():
|
||||
"""Run all rainbow tests continuously"""
|
||||
print("Starting rainbow test suite...")
|
||||
print("Runs all tests in sequence, then repeats")
|
||||
print("Press Ctrl+C to stop")
|
||||
|
||||
# Load settings
|
||||
settings = Settings()
|
||||
|
||||
# Initialize patterns using settings
|
||||
p = patterns.Patterns(
|
||||
pin=settings["led_pin"],
|
||||
num_leds=settings["num_leds"],
|
||||
brightness=255,
|
||||
delay=1000
|
||||
)
|
||||
|
||||
print(f"LED Pin: {settings['led_pin']}")
|
||||
print(f"LEDs: {settings['num_leds']}")
|
||||
print(f"Base Brightness: {p.brightness}")
|
||||
|
||||
# Initialize watchdog timer
|
||||
global wdt
|
||||
wdt = WDT(timeout=10000)
|
||||
wdt.feed()
|
||||
|
||||
# Test configurations
|
||||
tests = [
|
||||
("Test 1: Single node (full spectrum)", 1, 3000, 255, 12000),
|
||||
("Test 2: Two nodes", 2, 2000, 255, 10000),
|
||||
("Test 3: Three nodes (RGB)", 3, 1500, 255, 9000),
|
||||
("Test 4: Four nodes (RYGB)", 4, 1000, 255, 8000),
|
||||
("Test 5: Six nodes (ROYGBP)", 6, 800, 255, 8000),
|
||||
("Test 6: Eight nodes", 8, 600, 255, 6000),
|
||||
("Test 7: Twelve nodes (fine gradation)", 12, 400, 255, 6000),
|
||||
("Test 8: Many nodes (20), slow cycle", 20, 2000, 255, 10000),
|
||||
("Test 9: Five nodes", 5, 1000, 255, 6000),
|
||||
]
|
||||
|
||||
cycle = 0
|
||||
try:
|
||||
while True:
|
||||
cycle += 1
|
||||
print(f"\n\n========== Starting Cycle {cycle} ==========")
|
||||
|
||||
for test_name, n1, delay, brightness, duration in tests:
|
||||
run_test_case(p, test_name, n1, delay, brightness, duration)
|
||||
|
||||
print("\n========== Cycle completed ==========\n")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\n\nStopping test suite...")
|
||||
p.run = False
|
||||
p.off()
|
||||
print("LEDs turned off")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_rainbow_suite()
|
||||
|
||||
Reference in New Issue
Block a user