the REPL says the following
File "adafruit_led_animation/sequence.py", line 197, in animate
File "/lib/adafruit_led_animation/group.py", line 156, in animate
File "adafruit_led_animation/animation/__init__.py", line 96, in animate
File "/lib/adafruit_led_animation/animation/sparkle.py", line 81, in on_cycle_complete
File "/lib/adafruit_led_animation/group.py", line 112, in _group_done
File "/lib/adafruit_led_animation/group.py", line 123, in on_cycle_complete
File "adafruit_led_animation/sequence.py", line 133, in _sequence_complete
File "adafruit_led_animation/sequence.py", line 160, in _advance
File "adafruit_led_animation/sequence.py", line 179, in next
File "adafruit_led_animation/sequence.py", line 129, in on_cycle_complete
I will post all the entire script just so Im not leaving anything out but the problem part seems to be
def on_cycle_complete in the sparkle animation. i've tried for hours to see what the issue is but so long as that callback is in sparkle it seems to run to sequence.py's version of it instead.
Code: Select all
import random
from adafruit_led_animation.animation import Animation
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git"
class Sparkle(Animation):
# pylint: disable=too-many-arguments
def __init__(
self, pixel_object, speed, color, num_sparkles=1, name=None, mask=None
):
if len(pixel_object) < 2:
raise ValueError("Sparkle needs at least 2 pixels")
if mask:
self._mask = mask
else:
self._mask = []
if len(self._mask) >= len(pixel_object):
raise ValueError("Sparkle mask should be smaller than number pixel array")
self._half_color = color
self._dim_color = color
self._sparkle_color = color
self._num_sparkles = num_sparkles
self._num_pixels = len(pixel_object)
self._pixels = []
# self.add_cycle_complete_receiver(animation, callback)
super().__init__(pixel_object, speed, color, name=name)
on_cycle_complete_supported = True
def on_cycle_complete(self):
self.cycle_count += 1
print("cycle complete called")
if self.cycle_count % self.notify_cycles == 0:
for callback in self._also_notify:
callback(self) #This is the part that seems to create a domino effect of tracebacks/references out of scope
def _set_color(self, color):
half_color = tuple(color[rgb] // 4 for rgb in range(len(color)))
dim_color = tuple(color[rgb] // 10 for rgb in range(len(color)))
for pixel in range( # pylint: disable=consider-using-enumerate
len(self.pixel_object)
):
if self.pixel_object[pixel] == self._half_color:
self.pixel_object[pixel] = half_color
elif self.pixel_object[pixel] == self._dim_color:
self.pixel_object[pixel] = dim_color
self._half_color = half_color
self._dim_color = dim_color
self._sparkle_color = color
def _random_in_mask(self):
if len(self._mask) == 0:
return random.randint(0, (len(self.pixel_object) - 1))
return self._mask[random.randint(0, (len(self._mask) - 1))]
def draw(self):
self._pixels = [self._random_in_mask() for _ in range(self._num_sparkles)]
for pixel in self._pixels:
self.pixel_object[pixel] = self._sparkle_color
if self.draw_count % len(self.pixel_object) == 0:
print("animation has reached end of pixel array")
self.cycle_complete = True
def after_draw(self):
self.show()
for pixel in self._pixels:
self.pixel_object[pixel % self._num_pixels] = self._half_color
if (pixel + 1) % self._num_pixels in self._mask:
self.pixel_object[(pixel + 1) % self._num_pixels] = self._dim_color
def reset(self):
print("diminishing returns")