Refactor n_chase pattern for bidirectional movement
- Updated n_chase to support bidirectional movement with n3 and n4 parameters - n3 controls forward steps per direction change - n4 controls backward steps per direction change - Pattern alternates between moving forward n3 steps and backward n4 steps - Each direction repeats for the specified number of steps before switching - Added test/9.py with n1=20, n2=20, n3=20, n4=-5 parameters - Updated to run as a thread-based pattern similar to other patterns
This commit is contained in:
62
test/n_chase/9.py
Normal file
62
test/n_chase/9.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
N-chase test 9: Cyan, on=20, off=20, delay=200ms
|
||||
Runs forever
|
||||
Run with: mpremote run test/n_chase/9.py
|
||||
"""
|
||||
|
||||
import patterns
|
||||
import utime
|
||||
from settings import Settings
|
||||
from machine import WDT
|
||||
|
||||
print("Starting N-Chase Test 9: Cyan, on=20, off=20, delay=200ms")
|
||||
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=200
|
||||
)
|
||||
|
||||
# Configure test parameters
|
||||
p.n1 = 20 # On width 20
|
||||
p.n2 = 20 # Off width 20
|
||||
p.n3 = 20 # Reserved for future use
|
||||
p.n4 = -5 # Reserved for future use
|
||||
p.colors = [(0, 255, 255)] # Cyan
|
||||
|
||||
print(f"LED Pin: {settings['led_pin']}")
|
||||
print(f"LEDs: {settings['num_leds']}")
|
||||
print(f"Brightness: {p.brightness}")
|
||||
print(f"Delay: {p.delay}ms")
|
||||
print(f"On width: {p.n1}")
|
||||
print(f"Off width: {p.n2}")
|
||||
print(f"n3: {p.n3}")
|
||||
print(f"n4: {p.n4}")
|
||||
print(f"Color: {p.colors[0]}")
|
||||
|
||||
# Initialize watchdog timer
|
||||
wdt = WDT(timeout=10000)
|
||||
wdt.feed()
|
||||
|
||||
# Start pattern
|
||||
p.select("nc")
|
||||
print("Pattern started. Running forever...")
|
||||
|
||||
# Run forever
|
||||
try:
|
||||
while True:
|
||||
wdt.feed()
|
||||
utime.sleep_ms(100)
|
||||
except KeyboardInterrupt:
|
||||
print("\nStopping...")
|
||||
p.run = False
|
||||
p.off()
|
||||
print("LEDs turned off")
|
||||
|
||||
Reference in New Issue
Block a user