Skip to content

Nesting AnimateOnce inside AnimationSequence causes random animation order #91

@dhalbert

Description

@dhalbert

A user commented on this: https://forums.adafruit.com/viewtopic.php?f=60&t=186732

This (simplified) example, after the first round, does the red and blue animations in random order. Each Pulse animation is correct, but, successive Pulses do not strictly alternate between red and blue. Note the AnimateOnce inside AnimationSequence.

import board
import neopixel
from adafruit_led_animation.animation.pulse import Pulse
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.sequence import AnimateOnce
from adafruit_led_animation.color import RED, BLUE


num_pixels = 24

pixels = neopixel.NeoPixel(board.A0, num_pixels, auto_write=False)
pixels.brightness = 0.2

pulse0 = Pulse(pixels, speed=.05, color=RED, period=1)
pulse1 = Pulse(pixels, speed=.05, color=BLUE, period=1)

animations = AnimationSequence(
    AnimateOnce(pulse0,pulse1,),
    auto_clear=True,
    auto_reset=True,
    advance_interval=5,
)

while True:
        animations.animate()

Removing the nesting works fine. Red and blue alternate, as expected.

import board
import neopixel
from adafruit_led_animation.animation.pulse import Pulse
from adafruit_led_animation.sequence import AnimateOnce
from adafruit_led_animation.color import RED, BLUE

num_pixels = 24

pixels = neopixel.NeoPixel(board.A0, num_pixels, auto_write=False)
pixels.brightness = 0.2

pulse0 = Pulse(pixels, speed=.05, color=RED, period=1)
pulse1 = Pulse(pixels, speed=.05, color=BLUE, period=1)

animations = AnimateOnce(pulse0,pulse1,
                         auto_clear=True,
                         auto_reset=True,
                         advance_interval=5,
)

while True:
        animations.animate()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions