Add n3 step rate functionality to patterns

This commit is contained in:
2025-09-18 20:35:21 +12:00
parent 1275d60aaa
commit 748ad4b507
2 changed files with 36 additions and 27 deletions

View File

@@ -12,6 +12,7 @@ class Patterns(PatternBase): # Inherit from PatternBase
self.off_width = 2 # Default off width (so total segment is 3, matching original behavior)
self.n1 = 0 # Default start of fill range
self.n2 = self.num_leds - 1 # Default end of fill range
self.n3 = 1 # Default step factor
self.oneshot = False # New: One-shot flag for patterns like fill_range
self.patterns = {
"flicker": self.flicker,
@@ -28,15 +29,17 @@ class Patterns(PatternBase): # Inherit from PatternBase
def flicker(self):
current_time = utime.ticks_ms()
base_color = self.colors[0]
# Increase the range for flicker_brightness_offset
# Changed from self.brightness // 4 to self.brightness // 2 (or even self.brightness for max intensity)
# Use fixed minimum brightness of 10, flicker between 10 and full brightness
# Use n3 as step rate multiplier to control how fast patterns step
min_brightness = 10
step_rate = max(1, int(self.n3))
flicker_brightness_offset = random.randint(-int(self.brightness // 1.5), int(self.brightness // 1.5))
flicker_brightness = max(0, min(255, self.brightness + flicker_brightness_offset))
flicker_brightness = max(min_brightness, min(255, self.brightness + flicker_brightness_offset))
flicker_color = self.apply_brightness(base_color, brightness_override=flicker_brightness)
self.fill(flicker_color)
self.last_update = current_time
return max(1, int(self.delay // 5))
return max(1, int(self.delay // (5 * step_rate)))
def fill_range(self):
"""
@@ -61,6 +64,7 @@ class Patterns(PatternBase): # Inherit from PatternBase
A theater chase pattern using n1 for on-width and n2 for off-width.
"""
current_time = utime.ticks_ms()
step_rate = max(1, int(self.n3))
segment_length = self.n1 + self.n2
if segment_length == 0: # Avoid division by zero
self.fill((0,0,0))
@@ -74,7 +78,7 @@ class Patterns(PatternBase): # Inherit from PatternBase
else:
self.n[i] = (0, 0, 0)
self.n.write()
self.pattern_step = (self.pattern_step + 1) % segment_length
self.pattern_step = (self.pattern_step + step_rate) % segment_length
self.last_update = current_time
return self.delay
@@ -166,11 +170,12 @@ class Patterns(PatternBase): # Inherit from PatternBase
pos -= 170
return (0, pos * 3, 255 - pos * 3)
step_rate = max(1, int(self.n3))
for i in range(self.num_leds):
rc_index = (i * 256 // max(1, self.num_leds)) + self.pattern_step
self.n[i] = self.apply_brightness(wheel(rc_index & 255))
self.n.write()
self.pattern_step = (self.pattern_step + 1) % 256
self.pattern_step = (self.pattern_step + step_rate) % 256
return max(1, int(self.delay // 5))
def specto(self):