Sparkle
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.
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 thepixel_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 to5if no period is provided. -
max_intensity: The maximum intensity to pulse. Provide a value between0and1.0. Defaults to1. -
min_intensity: The minimum intensity to pulse. Provide a value between0and1.0. Defaults to0.
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.
# 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.color import AMBER, JADE
from adafruit_led_animation.sequence import AnimationSequence
# 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()
Page last edited January 22, 2025
Text editor powered by tinymce.