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=255, # Full 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 = 50 # Min brightness 50
|
|
p.brightness = 255 # Max brightness 255
|
|
p.delay = 3000 # 3 second cycle
|
|
p.colors = [(255, 0, 0)] # Red
|
|
run_test_case(p, "Test 1: Slow breathing (50-255 brightness)", 12000)
|
|
|
|
# Test Case 2: Fast pulsing
|
|
p.n1 = 100 # Min brightness 100
|
|
p.brightness = 255 # Max brightness 255
|
|
p.delay = 500 # 0.5 second cycle
|
|
p.colors = [(0, 255, 0)] # Green
|
|
run_test_case(p, "Test 2: Fast pulsing (100-255 brightness)", 8000)
|
|
|
|
# Test Case 3: Medium breathing
|
|
p.n1 = 80 # Min brightness 80
|
|
p.brightness = 255 # Max brightness 255
|
|
p.delay = 1500 # 1.5 second cycle
|
|
p.colors = [(0, 0, 255)] # Blue
|
|
run_test_case(p, "Test 3: Medium breathing (80-255 brightness)", 10000)
|
|
|
|
# Test Case 4: Very slow breathing
|
|
p.n1 = 150 # Min brightness 150
|
|
p.brightness = 255 # Max brightness 255
|
|
p.delay = 5000 # 5 second cycle
|
|
p.colors = [(255, 255, 0)] # Yellow
|
|
run_test_case(p, "Test 4: Very slow breathing (150-255 brightness)", 15000)
|
|
|
|
# Test Case 5: Very fast pulsing
|
|
p.n1 = 50 # Min brightness 50
|
|
p.brightness = 255 # Max brightness 255
|
|
p.delay = 200 # 0.2 second cycle
|
|
p.colors = [(255, 0, 255)] # Magenta
|
|
run_test_case(p, "Test 5: Very fast pulsing (50-255 brightness)", 6000)
|
|
|
|
# Test Case 6: Low range, slow cycle
|
|
p.n1 = 200 # Min brightness 200
|
|
p.brightness = 255 # Max brightness 255
|
|
p.delay = 4000 # 4 second cycle
|
|
p.colors = [(0, 255, 255)] # Cyan
|
|
run_test_case(p, "Test 6: Low range, slow cycle (200-255 brightness)", 12000)
|
|
|
|
# Test Case 7: High range, medium cycle
|
|
p.n1 = 100 # Min brightness 100
|
|
p.brightness = 255 # Max brightness 255
|
|
p.delay = 1000 # 1 second cycle
|
|
p.colors = [(255, 128, 0)] # Orange
|
|
run_test_case(p, "Test 7: High range, medium cycle (100-255 brightness)", 8000)
|
|
|
|
# Test Case 8: Ultra fast strobe
|
|
p.n1 = 100 # Min brightness 100
|
|
p.brightness = 255 # Max brightness 255
|
|
p.delay = 100 # 0.1 second cycle
|
|
p.colors = [(128, 0, 255)] # Purple
|
|
run_test_case(p, "Test 8: Ultra fast strobe (100-255 brightness)", 4000)
|
|
|
|
print("\n=== All tests completed ===")
|
|
|
|
# Turn off LEDs
|
|
p.off()
|
|
print("LEDs turned off")
|
|
|
|
if __name__ == "__main__":
|
|
test_sine_brightness()
|