The LED Animation library makes displaying animations on LEDs super simple. You've gone through the basic animations and how to use each of them individually. What if you want to run multiple animations in sequence? The LED Animation library has you covered with AnimationSequence.

AnimationSequence allows you to display multiple animations in a sequence, with a definable interval and a few other customisation options including clearing the pixels between animations and displaying them in a random order.

To use it, you'll want to include the following in your imports.

from adafruit_led_animation.sequence import AnimationSequence

The rest of the imports and setup is the same, however, you'll want to include multiple animations this time. This example for the NeoPixel FeatherWing includes blink, comet, and chase. You'll create the pixel object and the animations the same way you did in the previous sections.

import board
import neopixel

from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.color import PURPLE, AMBER, JADE

pixel_pin = board.D6
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)

blink = Blink(pixels, speed=0.5, color=JADE)
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=AMBER)

Next, you'll create the AnimationSequence object. AnimationSequence takes up to six arguments, but you're most commonly going to use a combination these four:

  • members:  The animation objects or groups, e.g. comet, blink, chase.
  • advance_interval: Time in seconds between animations if cycling automatically, e.g. 5. Defaults to None - it will not advance if an interval is not provided.
  • auto_clear: Clear the pixels between animations. Set to True to enable. Defaults to False.
  • random_order: Activate the animations in a random order. Set to True to enable. Defaults to False.

Check out the API documentation for information on the other two.

animations = AnimationSequence(
    comet, blink, chase, advance_interval=5, auto_clear=True, random_order=True
)

Finally, you'll display the animations.

while True:
    animations.animate()

Now you can display multiple animations in a sequence! Now we'll take a look at some more animations. Next up: rainbows!

Full Example Code

This example displays three animations in a sequence, at a 5 second interval, and in a random order.

# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT

"""
This example uses AnimationsSequence to display multiple animations in sequence, at a five second
interval.

For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
a different form of NeoPixels.
"""
import board
import neopixel

from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.color import PURPLE, AMBER, JADE

# Update to match the pin connected to your NeoPixels
pixel_pin = board.D6
# Update to match the number of NeoPixels you have connected
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

blink = Blink(pixels, speed=0.5, color=JADE)
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=AMBER)


animations = AnimationSequence(blink, comet, chase, advance_interval=3, auto_clear=True)

while True:
    animations.animate()

This guide was first published on May 27, 2020. It was last updated on Mar 29, 2024.

This page (Animation Sequence) was last updated on Mar 29, 2024.

Text editor powered by tinymce.