The CircuitPython LED Animation library includes a series of sparkle animations: sparkle and sparklepulse. This section will cover these animations and the available customizations for each of them.

Most animations will run individually on the SAMD21 (M0) microcontroller boards, but some combinations of animations and the most complex animations will not. Check out the FAQ for details. If you're interested in running all the animations, or many animations together, consider using at least a SAMD51 (M4) microcontroller.

Sparkle

This animation sparkles across all of the pixels in a single color.

First, you import the Sparkle module and a color for it. See Import and Setup for the rest of the necessary imports and pixel object creation.

from adafruit_led_animation.animation.sparkle import Sparkle
from adafruit_led_animation.color import AMBER

Next you create the Sparkle animation. Sparkle requires two arguments, and has an optional third.

Required:

  • pixel_object: The pixel object, e.g. pixels.
  • speed: The refresh rate of the sparkle in seconds, e.g. 0.05.
  • color: The color to display, e.g. AMBER. Can also be a color tuple, e.g. (255, 0, 0), or a hex color value, e.g. 0xFF0000.

Optional:

  • num_sparkles: The number of sparkles. Defaults to 5% of the length of the pixel_object.

Once created, you display the animation.

sparkle = Sparkle(pixels, speed=0.05, color=AMBER, num_sparkles=10)

while True:
    sparkle.animate()

SparklePulse

This is a version of sparkle that uses pulse to determine the brightness of each pixel.

First, you import the SparklePulse module and a color for it. See Import and Setup for the rest of the necessary imports and pixel object creation.

from adafruit_led_animation.animation.SparklePulse import SparklePulse
from adafruit_led_animation.color import JADE

Next you create the SparklePulse animation. SparklePulse requires three arguments, and has an optional three more.

Required:

  • pixel_object: The pixel object, e.g. pixels.
  • speed: The speed of the pulse in seconds, e.g. 0.05.
  • color: The color to display, e.g. JADE. Can also be a color tuple, e.g. (255, 0, 0), or a hex color value, e.g. 0xFF0000.

Optional:

  • period: The number of seconds over which to pulse the LEDs. Defaults to 5 if no period is provided.
  • max_intensity: The maximum intensity to pulse. Provide a value between 0 and 1.0. Defaults to 1.
  • min_intensity: The minimum intensity to pulse. Provide a value between 0 and 1.0. Defaults to 0.

Once created, you display the animation.

sparkle_pulse = SparklePulse(pixels, speed=0.05, period=3, color=JADE)

while True:
    sparkle_pulse.animate()

Next we'll look at using the pixel mapping helpers to create a grid from a single LED strip.

Full Example Code

This example displays the sparkle animations in sequence.

# 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.sparkle import Sparkle
from adafruit_led_animation.animation.sparklepulse import SparklePulse
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.color import 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)

sparkle = Sparkle(pixels, speed=0.05, color=AMBER, num_sparkles=10)
sparkle_pulse = SparklePulse(pixels, speed=0.05, period=3, color=JADE)

animations = AnimationSequence(
    sparkle,
    sparkle_pulse,
    advance_interval=5,
    auto_clear=True,
)

while True:
    animations.animate()

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

This page (Sparkle) was last updated on May 31, 2023.

Text editor powered by tinymce.