From 545ff966c8022a0582de682379eb3aa230c579a2 Mon Sep 17 00:00:00 2001 From: Pearu Vaalma Date: Sun, 21 Dec 2025 14:54:56 +0000 Subject: [PATCH] add generated christmas lights (#9) Reviewed-on: https://git.lapikud.ee/pvx/litsimaja/pulls/9 --- pyleds/program/promise/ChristmasLights.py | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pyleds/program/promise/ChristmasLights.py diff --git a/pyleds/program/promise/ChristmasLights.py b/pyleds/program/promise/ChristmasLights.py new file mode 100644 index 0000000..e0b44f6 --- /dev/null +++ b/pyleds/program/promise/ChristmasLights.py @@ -0,0 +1,38 @@ +from lib.Program import Program +from rpi_ws281x import Color +import time + +def name(): + return 'Christmas Lights' + +class ChristmasLights(Program): + def run(self, args: [] = None): + # Configuration + wait_ms = 0 # Speed of the animation + + # Define classic festive colors + RED = Color(255, 0, 0) + GREEN = Color(0, 255, 0) + WARM_WHITE = Color(200, 180, 60) # A golden-ish warm white + + colors = [RED, GREEN, WARM_WHITE] + + # This determines how many pixels of the same color are next to each other + group_size = 2 + + offset = 0 + while self.get_loop().status(): + 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.show() + + # Increment offset to move the lights + offset = (offset + 1) % (len(colors) * group_size) + self._lm.get_tempo().wait() + time.sleep(wait_ms / 1000.0)