From f35c13950ca84783dda2d20d814304a805f86228 Mon Sep 17 00:00:00 2001 From: Will Ridgers Date: Fri, 1 Mar 2024 20:04:37 +0000 Subject: [PATCH] Add cylon effect Example config: [led_effect bed_idle] autostart: true frame_rate: 30 leds: neopixel:bed_lights layers: cylon 0.75 1 top (1,0,0),(0,1,0),(0,0,1) --- docs/LED_Effect.md | 7 +++++++ src/led_effect.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/docs/LED_Effect.md b/docs/LED_Effect.md index 7b0dc5a..56c48fd 100644 --- a/docs/LED_Effect.md +++ b/docs/LED_Effect.md @@ -326,6 +326,13 @@ the "head" of the comet and the remaining colors are blended into the "tail" Palette: Color of "head" and gradient of "tail" Identical settings as Comet, but with multiple lights chasing each other. +#### Cylon + Effect Rate: 1 How fast the cylon sweeps + Cutoff: 0 Not used but must be provided + Palette: Color of sweeping LED +A light moves between each end of the strip. Multiple colors can be provided; +the color will change after each sweep. + #### Heater Effect Rate: 1 Minimum temperature to activate effect Cutoff: 0 Disable effect once temp is reached diff --git a/src/led_effect.py b/src/led_effect.py index e00c864..05488a6 100644 --- a/src/led_effect.py +++ b/src/led_effect.py @@ -822,6 +822,40 @@ def __init__(self, **kwargs): self.frameCount = len(self.thisFrame) + #Cylon, single LED bounces from start to end of strip + class layerCylon(_layerBase): + def __init__(self, **kwargs): + super(ledEffect.layerCylon, self).__init__(**kwargs) + + self.paletteColors = colorArray(COLORS, self.paletteColors) + + if self.effectRate <= 0: + raise Exception("effect rate for cylon must be > 0") + + # How many frames per sweep animation. + frames = int(self.effectRate / self.frameRate) + + direction = True + + for _ in range(len(self.paletteColors) % 2 + 1): + for c in range(0, len(self.paletteColors)): + color = self.paletteColors[c] + + for frame in range(frames): + pct = frame / (frames - 1) + newFrame = [] + + p = int(round((self.ledCount - 2) * pct) if direction else 1 + round(((self.ledCount - 2) * (1 - pct)))) + + for i in range(self.ledCount): + newFrame += color if p == i else [0.0] * COLORS + + self.thisFrame.append(newFrame) + + direction = not direction + + self.frameCount = len(self.thisFrame) + #Color gradient over all LEDs class layerGradient(_layerBase): def __init__(self, **kwargs):