fix(led-driver): phase-lock pattern timers
Made-with: Cursor
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user