fix(led-driver): phase-lock pattern timers

Made-with: Cursor
This commit is contained in:
2026-04-19 21:41:18 +12:00
parent 45a38c05b7
commit 22b1a8a6d6
4 changed files with 10 additions and 5 deletions

View File

@@ -28,6 +28,6 @@ class Blink:
# "Off" phase: turn all LEDs off
self.driver.fill((0, 0, 0))
state = not state
last_update = current_time
last_update = utime.ticks_add(last_update, delay_ms)
# Yield once per tick so other logic can run
yield

View File

@@ -118,7 +118,8 @@ class Chase:
# Increment step
step_count += 1
self.driver.step = step_count
last_update = current_time
last_update = utime.ticks_add(last_update, transition_duration)
transition_duration = max(10, int(preset.d))
# Yield once per tick so other logic can run
yield

View File

@@ -62,7 +62,9 @@ class Circle:
# Move head continuously at n1 LEDs per second
if utime.ticks_diff(current_time, last_head_move) >= head_delay:
head = (head + 1) % self.driver.num_leds
last_head_move = current_time
last_head_move = utime.ticks_add(last_head_move, head_delay)
head_rate = max(1, int(preset.n1))
head_delay = 1000 // head_rate
# Tail behavior based on phase
if phase == "growing":
@@ -73,7 +75,9 @@ class Circle:
# Shrinking phase: move tail forward at n3 LEDs per second
if utime.ticks_diff(current_time, last_tail_move) >= tail_delay:
tail = (tail + 1) % self.driver.num_leds
last_tail_move = current_time
last_tail_move = utime.ticks_add(last_tail_move, tail_delay)
tail_rate = max(1, int(preset.n3))
tail_delay = 1000 // tail_rate
# Check if we've reached min length
current_length = (head - tail) % self.driver.num_leds

View File

@@ -46,6 +46,6 @@ class Rainbow:
self.driver.n.write()
step = (step + step_amount) % 256
self.driver.step = step
last_update = current_time
last_update = utime.ticks_add(last_update, sleep_ms)
# Yield once per tick so other logic can run
yield