From b65c8c1eab242614bbac62604f3c24fab0c619a1 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Wed, 25 Aug 2021 05:36:42 +0200 Subject: [PATCH] Fix setting a pixels slice When setting the pixels with a slice, set the correct pixel to a value provided (not to the index). This was discovered using `adafruit_led_animation.animation.rainbow` ```py from adafruit_led_animation.animation.rainbow import Rainbow rainbow = Rainbow(macropad.pixels, speed=.1, period=2) while True: rainbow.animate() ``` And tested with this (with all values of rotation) ```py from adafruit_macropad import MacroPad import time macropad = MacroPad(rotation=0) macropad.pixels[:] = ( (255,0,0), (128,255,0), (0,255,0), (0,255,128), (0,0,255), (128,0,255), (255,255,255), (0,0,0), (255,0,0), (128,255,0), (0,255,0), (0,255,128), ) time.sleep(2) for x in range(9): macropad.pixels.fill(0) macropad.pixels[x:x+4] = ( (255,0,0), (0,255,0), (0,0,255), (255,255,255) ) time.sleep(1) ``` --- adafruit_macropad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_macropad.py b/adafruit_macropad.py index 98f890c..a1b33fa 100755 --- a/adafruit_macropad.py +++ b/adafruit_macropad.py @@ -925,7 +925,7 @@ def __init__(self, pixels, order=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)): def __setitem__(self, index, val): if isinstance(index, slice): for val_i, in_i in enumerate(range(*index.indices(self._num_pixels))): - self._pixels[in_i] = self._order[val_i] + self._pixels[self._order[in_i]] = val[val_i] else: self._pixels[self._order[index]] = val