Skip to content

Commit c209281

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

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

library/rpi_ws281x/rpi_ws281x.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,14 @@ def __len__(self):
224224

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

230236
def setPixelColorRGB(self, n, red, green, blue, white=0):
231237
"""Set LED at position n to the provided red, green, and blue color.
@@ -269,6 +275,10 @@ def getPixelColorRGBW(self, n):
269275
def show(self):
270276
self.strip.show()
271277

278+
def off(self):
279+
self.strip[self.first:self.last] = 0
280+
self.strip.show()
281+
272282
# Shim for back-compatibility
273283
class Adafruit_NeoPixel(PixelStrip):
274284
pass

0 commit comments

Comments
 (0)