@@ -102,6 +102,7 @@ def __init__(self, num, pin, freq_hz=800000, dma=10, invert=False,
102
102
self .getPixelColor = self .main_strip .getPixelColor
103
103
self .getPixelColorRGB = self .main_strip .getPixelColorRGB
104
104
self .getPixelColorRGBW = self .main_strip .getPixelColorRGBW
105
+ self .off = self .main_strip .off
105
106
106
107
# Substitute for __del__, traps an exit condition and cleans up properly
107
108
atexit .register (self ._cleanup )
@@ -224,8 +225,14 @@ def __len__(self):
224
225
225
226
def setPixelColor (self , n , color ):
226
227
"""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.
227
230
"""
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
229
236
230
237
def setPixelColorRGB (self , n , red , green , blue , white = 0 ):
231
238
"""Set LED at position n to the provided red, green, and blue color.
@@ -269,6 +276,10 @@ def getPixelColorRGBW(self, n):
269
276
def show (self ):
270
277
self .strip .show ()
271
278
279
+ def off (self ):
280
+ self .strip [self .first :self .last ] = 0
281
+ self .strip .show ()
282
+
272
283
# Shim for back-compatibility
273
284
class Adafruit_NeoPixel (PixelStrip ):
274
285
pass
0 commit comments