5 Commits

Author SHA1 Message Date
topsinoty
750f1100a6 refactor: read the code and remake to match DiskoPidu 2026-01-02 02:36:11 +02:00
topsinoty
ffa77db057 use _lm.tempo and set sleep to 0 2025-12-21 16:10:41 +02:00
topsinoty
a71201d90a change to pascal case. 2025-12-21 16:01:37 +02:00
topsinoty
d811b853a1 change lib source to module 2025-12-21 15:54:53 +02:00
topsinoty
6d9c4b2f33 add generated christmas lights 2025-12-21 15:31:39 +02:00
2 changed files with 21 additions and 35 deletions

View File

@@ -1,14 +0,0 @@
from lib.Program import Program
def name():
return '2-color strips'
class Strips(Program):
def run(self, args = None) -> None:
for i in range(self._lm.count_pixels()):
if i // 5 % 2:
color = (255, 255, 255)
else:
color = args['color']
self._lm.set_pixel_color(i, (color[0] << 16) | (color[1] << 8) | color[2])
self._lm.show()

View File

@@ -6,33 +6,33 @@ def name():
return 'Christmas Lights' return 'Christmas Lights'
class ChristmasLights(Program): class ChristmasLights(Program):
def run(self, args: [] = None):
# Configuration
wait_ms = 0 # Speed of the animation
# Define classic festive colors def christmas_pattern(self, offset, segment_length=2):
RED = Color(255, 0, 0) RED = Color(255, 0, 0)
GREEN = Color(0, 255, 0) GREEN = Color(0, 255, 0)
WARM_WHITE = Color(200, 180, 60) # A golden-ish warm white WARM_WHITE = Color(200, 180, 60)
colors = [RED, GREEN, WARM_WHITE] colors = [RED, GREEN, WARM_WHITE]
# This determines how many pixels of the same color are next to each other totalLength = self._lm.count_pixels()
group_size = 2
offset = 0 for i in range(totalLength):
while self.get_loop().status(): color_index = ((i + offset) // segment_length) % len(colors)
num_pixels = self._lm.count_pixels()
for i in range(num_pixels):
# Calculate which color index to use based on pixel position and current offset
# This creates the "moving" effect
color_index = ((i + offset) // group_size) % len(colors)
self._lm.set_pixel_color(i, colors[color_index]) self._lm.set_pixel_color(i, colors[color_index])
self._lm.show() self._lm.show()
return len(colors) * segment_length
# Increment offset to move the lights def run(self, args=None):
offset = (offset + 1) % (len(colors) * group_size) # Fsr the application in the run file is different from
# the configuration in the Program and ProgramLoading files
loop = args.get("loop", False) if args else False
offset = 0
segment_length = 2
while self.get_loop().status():
self._lm.get_tempo().wait() self._lm.get_tempo().wait()
time.sleep(wait_ms / 1000.0) cycle_limit = self.christmas_pattern(offset, segment_length)
offset = (offset + 1) % cycle_limit
if not loop:
break