File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -106,14 +106,19 @@ def __getitem__(self, pos):
106
106
107
107
def __setitem__ (self , pos , value ):
108
108
"""Set the 24-bit RGB color value at the provided position or slice of
109
- positions.
109
+ positions. If value is a slice it is zip()'ed with pos to set as many
110
+ leds as there are values.
110
111
"""
111
112
# Handle if a slice of positions are passed in by setting the appropriate
112
113
# LED data values to the provided value.
113
114
# Cast to int() as value may be a numpy non-int value.
114
115
if isinstance (pos , slice ):
115
- for n in range (* pos .indices (self .size )):
116
- ws .ws2811_led_set (self ._channel , n , int (value ))
116
+ try :
117
+ for n , c in zip (range (* pos .indices (self .size )), value ):
118
+ ws .ws2811_led_set (self ._channel , n , int (c ))
119
+ except TypeError :
120
+ for n in range (* pos .indices (self .size )):
121
+ ws .ws2811_led_set (self ._channel , n , int (value ))
117
122
# Else assume the passed in value is a number to the position.
118
123
else :
119
124
return ws .ws2811_led_set (self ._channel , pos , int (value ))
You can’t perform that action at this time.
0 commit comments