Skip to content

Commit e64f0ae

Browse files
committed
Add off() and let SetColorXX() handle slices of colors too.
Signed-off-by: David Greaves <[email protected]>
1 parent c18f162 commit e64f0ae

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

library/rpi_ws281x/rpi_ws281x.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(self, num, pin, freq_hz=800000, dma=10, invert=False,
102102
self.getPixelColor = self.main_strip.getPixelColor
103103
self.getPixelColorRGB = self.main_strip.getPixelColorRGB
104104
self.getPixelColorRGBW = self.main_strip.getPixelColorRGBW
105+
self.off = self.main_strip.off
105106

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

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

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

279+
def off(self):
280+
self.strip[self.first:self.last] = 0
281+
self.strip.show()
282+
272283
# Shim for back-compatibility
273284
class Adafruit_NeoPixel(PixelStrip):
274285
pass

0 commit comments

Comments
 (0)