57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
import utime
|
|
|
|
|
|
RED = (255, 0, 0)
|
|
|
|
|
|
class ScaleTest:
|
|
"""
|
|
Animated test for the scale() helper.
|
|
|
|
A single red pixel moves along the reference strip (strip 0). For each other
|
|
strip, the position is mapped using:
|
|
|
|
n2 = scale(l1, l2, n1)
|
|
|
|
so that all lit pixels stay aligned by proportional position along the strips.
|
|
"""
|
|
|
|
def __init__(self, driver):
|
|
self.driver = driver
|
|
|
|
def run(self, preset):
|
|
strips = self.driver.strips
|
|
if not strips:
|
|
return
|
|
|
|
src_strip_idx = 0
|
|
l1 = self.driver.strip_length(src_strip_idx)
|
|
if l1 <= 0:
|
|
return
|
|
|
|
step = self.driver.step
|
|
delay_ms = max(1, int(getattr(preset, "d", 30) or 30))
|
|
last_update = utime.ticks_ms()
|
|
color = self.driver.apply_brightness(RED, getattr(preset, "b", 255))
|
|
|
|
while True:
|
|
now = utime.ticks_ms()
|
|
if utime.ticks_diff(now, last_update) >= delay_ms:
|
|
n1 = step % l1
|
|
|
|
# Clear all strips
|
|
for strip in strips:
|
|
strip.fill((0, 0, 0))
|
|
|
|
# Light mapped position on each strip using Presets.set/show
|
|
for dst_strip_idx, _ in enumerate(strips):
|
|
self.driver.set(dst_strip_idx, n1, color)
|
|
self.driver.show(dst_strip_idx)
|
|
|
|
step += 1
|
|
self.driver.step = step
|
|
last_update = now
|
|
|
|
yield
|
|
|