Compare commits
1 Commits
dev
...
50545e3170
Author | SHA1 | Date | |
---|---|---|---|
50545e3170 |
@@ -14,11 +14,15 @@ class Patterns:
|
|||||||
self.patterns = {
|
self.patterns = {
|
||||||
"off": self.off,
|
"off": self.off,
|
||||||
"on" : self.on,
|
"on" : self.on,
|
||||||
|
"color_wipe": self.color_wipe_step,
|
||||||
"rainbow_cycle": self.rainbow_cycle_step,
|
"rainbow_cycle": self.rainbow_cycle_step,
|
||||||
"theater_chase": self.theater_chase_step,
|
"theater_chase": self.theater_chase_step,
|
||||||
"blink": self.blink_step,
|
"blink": self.blink_step,
|
||||||
"color_transition": self.color_transition_step, # Added new pattern
|
"color_transition": self.color_transition_step, # Added new pattern
|
||||||
"flicker": self.flicker_step,
|
"flicker": self.flicker_step,
|
||||||
|
"scanner": self.scanner_step, # New: Single direction scanner
|
||||||
|
"bidirectional_scanner": self.bidirectional_scanner_step, # New: Bidirectional scanner
|
||||||
|
"external": None
|
||||||
}
|
}
|
||||||
self.selected = selected
|
self.selected = selected
|
||||||
# Ensure colors list always starts with at least two for robust transition handling
|
# Ensure colors list always starts with at least two for robust transition handling
|
||||||
@@ -34,6 +38,9 @@ class Patterns:
|
|||||||
|
|
||||||
self.hold_start_time = utime.ticks_ms() # Time when the current color hold started
|
self.hold_start_time = utime.ticks_ms() # Time when the current color hold started
|
||||||
|
|
||||||
|
# New attributes for scanner patterns
|
||||||
|
self.scanner_direction = 1 # 1 for forward, -1 for backward
|
||||||
|
self.scanner_tail_length = 3 # Number of trailing pixels
|
||||||
|
|
||||||
def sync(self):
|
def sync(self):
|
||||||
self.pattern_step=0
|
self.pattern_step=0
|
||||||
@@ -43,6 +50,8 @@ class Patterns:
|
|||||||
self.current_color_idx = 0
|
self.current_color_idx = 0
|
||||||
self.current_color = self.colors[self.current_color_idx]
|
self.current_color = self.colors[self.current_color_idx]
|
||||||
self.hold_start_time = utime.ticks_ms() # Reset hold time
|
self.hold_start_time = utime.ticks_ms() # Reset hold time
|
||||||
|
# Reset scanner specific variables
|
||||||
|
self.scanner_direction = 1
|
||||||
self.tick()
|
self.tick()
|
||||||
|
|
||||||
def set_pattern_step(self, step):
|
def set_pattern_step(self, step):
|
||||||
@@ -312,3 +321,76 @@ class Patterns:
|
|||||||
flicker_color = self.apply_brightness(base_color, brightness_override=flicker_brightness)
|
flicker_color = self.apply_brightness(base_color, brightness_override=flicker_brightness)
|
||||||
self.fill(flicker_color)
|
self.fill(flicker_color)
|
||||||
self.last_update = current_time
|
self.last_update = current_time
|
||||||
|
|
||||||
|
def scanner_step(self):
|
||||||
|
"""
|
||||||
|
Mimics a 'Knight Rider' style scanner, moving in one direction.
|
||||||
|
"""
|
||||||
|
current_time = utime.ticks_ms()
|
||||||
|
if utime.ticks_diff(current_time, self.last_update) >= self.delay:
|
||||||
|
self.fill((0, 0, 0)) # Clear all LEDs
|
||||||
|
|
||||||
|
# Calculate the head and tail position
|
||||||
|
head_pos = self.pattern_step
|
||||||
|
color = self.apply_brightness(self.colors[0])
|
||||||
|
|
||||||
|
# Draw the head
|
||||||
|
if 0 <= head_pos < self.num_leds:
|
||||||
|
self.n[head_pos] = color
|
||||||
|
|
||||||
|
# Draw the trailing pixels with decreasing brightness
|
||||||
|
for i in range(1, self.scanner_tail_length + 1):
|
||||||
|
tail_pos = head_pos - i
|
||||||
|
if 0 <= tail_pos < self.num_leds:
|
||||||
|
# Calculate fading color for tail
|
||||||
|
# Example: linear fade from full brightness to off
|
||||||
|
fade_factor = 1.0 - (i / (self.scanner_tail_length + 1))
|
||||||
|
faded_color = tuple(int(c * fade_factor) for c in color)
|
||||||
|
self.n[tail_pos] = faded_color
|
||||||
|
|
||||||
|
self.n.write()
|
||||||
|
|
||||||
|
self.pattern_step += 1
|
||||||
|
if self.pattern_step >= self.num_leds + self.scanner_tail_length:
|
||||||
|
self.pattern_step = 0 # Reset to start
|
||||||
|
|
||||||
|
self.last_update = current_time
|
||||||
|
|
||||||
|
def bidirectional_scanner_step(self):
|
||||||
|
"""
|
||||||
|
Mimics a 'Knight Rider' style scanner, moving back and forth.
|
||||||
|
"""
|
||||||
|
current_time = utime.ticks_ms()
|
||||||
|
if utime.ticks_diff(current_time, self.last_update) >= self.delay/100:
|
||||||
|
self.fill((0, 0, 0)) # Clear all LEDs
|
||||||
|
|
||||||
|
color = self.apply_brightness(self.colors[0])
|
||||||
|
|
||||||
|
# Calculate the head position based on direction
|
||||||
|
head_pos = self.pattern_step
|
||||||
|
|
||||||
|
# Draw the head
|
||||||
|
if 0 <= head_pos < self.num_leds:
|
||||||
|
self.n[head_pos] = color
|
||||||
|
|
||||||
|
# Draw the trailing pixels with decreasing brightness
|
||||||
|
for i in range(1, self.scanner_tail_length + 1):
|
||||||
|
tail_pos = head_pos - (i * self.scanner_direction)
|
||||||
|
if 0 <= tail_pos < self.num_leds:
|
||||||
|
fade_factor = 1.0 - (i / (self.scanner_tail_length + 1))
|
||||||
|
faded_color = tuple(int(c * fade_factor) for c in color)
|
||||||
|
self.n[tail_pos] = faded_color
|
||||||
|
|
||||||
|
self.n.write()
|
||||||
|
|
||||||
|
self.pattern_step += self.scanner_direction
|
||||||
|
|
||||||
|
# Change direction if boundaries are reached
|
||||||
|
if self.scanner_direction == 1 and self.pattern_step >= self.num_leds:
|
||||||
|
self.scanner_direction = -1
|
||||||
|
self.pattern_step = self.num_leds - 1 # Start moving back from the last LED
|
||||||
|
elif self.scanner_direction == -1 and self.pattern_step < 0:
|
||||||
|
self.scanner_direction = 1
|
||||||
|
self.pattern_step = 0 # Start moving forward from the first LED
|
||||||
|
|
||||||
|
self.last_update = current_time
|
||||||
|
Reference in New Issue
Block a user