Skip to content

Commit

Permalink
Add off() and let SetColorXX() handle slices of colors too.
Browse files Browse the repository at this point in the history
Signed-off-by: David Greaves <[email protected]>
  • Loading branch information
lbt committed Dec 13, 2024
1 parent bc25da3 commit 164c5a0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion library/rpi_ws281x/rpi_ws281x.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(self, num, pin, freq_hz=800000, dma=10, invert=False,
self.getPixelColor = self.main_strip.getPixelColor
self.getPixelColorRGB = self.main_strip.getPixelColorRGB
self.getPixelColorRGBW = self.main_strip.getPixelColorRGBW
self.off = self.main_strip.off

# Substitute for __del__, traps an exit condition and cleans up properly
atexit.register(self._cleanup)
Expand Down Expand Up @@ -224,8 +225,14 @@ def __len__(self):

def setPixelColor(self, n, color):
"""Set LED at position n to the provided 24-bit color value (in RGB order).
If n is a slice then color can be a value which is repeated for all leds
or a slice of values which are applied to the leds.
"""
self.strip[self.first + n] = color
if isinstance(n, slice):
n = slice(n.start + self.first, n.stop + self.first, n.step)
else:
n = self.first + n
self.strip[n] = color

def setPixelColorRGB(self, n, red, green, blue, white=0):
"""Set LED at position n to the provided red, green, and blue color.
Expand Down Expand Up @@ -269,6 +276,10 @@ def getPixelColorRGBW(self, n):
def show(self):
self.strip.show()

def off(self):
self.strip[self.first:self.last] = 0
self.strip.show()

# Shim for back-compatibility
class Adafruit_NeoPixel(PixelStrip):
pass

0 comments on commit 164c5a0

Please sign in to comment.