121 lines
3.9 KiB
Python
121 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for sine brightness pattern
|
|
Run with: mpremote run test/sine_brightness.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} min brightness, brightness={p.brightness} max brightness, delay={p.delay}ms wavelength")
|
|
print(f"Color: {p.colors[0]}")
|
|
print(f"Running for {duration_ms//1000} seconds...")
|
|
|
|
# Initialize watchdog timer
|
|
wdt = WDT(timeout=10000)
|
|
wdt.feed()
|
|
|
|
# Start pattern
|
|
p.select("sb")
|
|
|
|
# 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_sine_brightness():
|
|
print("Testing sine brightness 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=51, # 20% brightness
|
|
delay=1000 # Base wavelength
|
|
)
|
|
|
|
print(f"LED Pin: {settings['led_pin']}")
|
|
print(f"LEDs: {settings['num_leds']}")
|
|
print(f"Base Brightness: {p.brightness}")
|
|
|
|
# Test Case 1: Slow breathing
|
|
p.n1 = 10 # Min brightness 10
|
|
p.brightness = 40 # Max brightness 40
|
|
p.delay = 3000 # 3 second cycle
|
|
p.colors = [(255, 0, 0)] # Red
|
|
run_test_case(p, "Test 1: Slow breathing (10-40 brightness)", 12000)
|
|
|
|
# Test Case 2: Fast pulsing
|
|
p.n1 = 5 # Min brightness 5
|
|
p.brightness = 51 # Max brightness 51
|
|
p.delay = 500 # 0.5 second cycle
|
|
p.colors = [(0, 255, 0)] # Green
|
|
run_test_case(p, "Test 2: Fast pulsing (5-51 brightness)", 8000)
|
|
|
|
# Test Case 3: Medium breathing
|
|
p.n1 = 15 # Min brightness 15
|
|
p.brightness = 45 # Max brightness 45
|
|
p.delay = 1500 # 1.5 second cycle
|
|
p.colors = [(0, 0, 255)] # Blue
|
|
run_test_case(p, "Test 3: Medium breathing (15-45 brightness)", 10000)
|
|
|
|
# Test Case 4: Very slow breathing
|
|
p.n1 = 20 # Min brightness 20
|
|
p.brightness = 30 # Max brightness 30
|
|
p.delay = 5000 # 5 second cycle
|
|
p.colors = [(255, 255, 0)] # Yellow
|
|
run_test_case(p, "Test 4: Very slow breathing (20-30 brightness)", 15000)
|
|
|
|
# Test Case 5: Very fast pulsing
|
|
p.n1 = 0 # Min brightness 0
|
|
p.brightness = 51 # Max brightness 51
|
|
p.delay = 200 # 0.2 second cycle
|
|
p.colors = [(255, 0, 255)] # Magenta
|
|
run_test_case(p, "Test 5: Very fast pulsing (0-51 brightness)", 6000)
|
|
|
|
# Test Case 6: Low range, slow cycle
|
|
p.n1 = 25 # Min brightness 25
|
|
p.brightness = 35 # Max brightness 35
|
|
p.delay = 4000 # 4 second cycle
|
|
p.colors = [(0, 255, 255)] # Cyan
|
|
run_test_case(p, "Test 6: Low range, slow cycle (25-35 brightness)", 12000)
|
|
|
|
# Test Case 7: High range, medium cycle
|
|
p.n1 = 5 # Min brightness 5
|
|
p.brightness = 51 # Max brightness 51
|
|
p.delay = 1000 # 1 second cycle
|
|
p.colors = [(255, 128, 0)] # Orange
|
|
run_test_case(p, "Test 7: High range, medium cycle (5-51 brightness)", 8000)
|
|
|
|
# Test Case 8: Ultra fast strobe
|
|
p.n1 = 0 # Min brightness 0
|
|
p.brightness = 51 # Max brightness 51
|
|
p.delay = 100 # 0.1 second cycle
|
|
p.colors = [(128, 0, 255)] # Purple
|
|
run_test_case(p, "Test 8: Ultra fast strobe (0-51 brightness)", 4000)
|
|
|
|
print("\n=== All tests completed ===")
|
|
|
|
# Turn off LEDs
|
|
p.off()
|
|
print("LEDs turned off")
|
|
|
|
if __name__ == "__main__":
|
|
test_sine_brightness()
|