The CircuitPython LED Animation library includes a series of rainbow animations: rainbow, rainbowchase, rainbowcomet, and rainbowsparkle. This section will cover these animations and the available customisations for each of them. Let's make some rainbows!
Rainbow
This animation displays a shifting rainbow across all the pixels with a number of customization options.
First, you import the Rainbow
module. See Import and Setup for the rest of the necessary imports and pixel object creation.
from adafruit_led_animation.animation.rainbow import Rainbow
Next you create the Rainbow
animation. Rainbow
requires two arguments, and has an optional three more.
Required:
-
pixel_object
: The pixel object, e.g.pixels
. -
speed
: The refresh rate of the rainbow in seconds, e.g.0.1
.
Optional:
-
period
: The period over which to cycle the rainbow in seconds, e.g.2
. Defaults to 5 if no period is provided. -
step
: The steps to take through the colorwheel (0-255). A step of1
means cycling through the entire colorwheel, a step of2
means it cycles through every other possible value. Defaults to1
if no step is provided. -
precompute_rainbow
: Precompute the rainbow which increases its speed, but uses more memory. Set toFalse
to disable if you are running into memory limitations. Defaults toTrue
.
Once created, you display the animation.
rainbow = Rainbow(pixels, speed=0.1, period=2) while True: rainbow.animate()
That's all there is to displaying a rainbow using the LED Animation library! Let's take a look at the next animation.
RainbowChase
This is a rainbow version of the theatre marquee type chase animation, with definable length of lit LEDs and the dark gap between lit LEDs.
First, you import the RainbowChase
module. See Import and Setup for the rest of the necessary imports and pixel object creation.
from adafruit_led_animation.animation.rainbowchase import RainbowChase
Next you create the RainbowChase
animation. RainbowChase
requires two arguments, and has an optional five more. You'll likely want to at least specify size
and spacing
.
Required:
-
pixel_object
: The pixel object, e.g.pixels
. -
speed
: The refresh rate of the rainbow in seconds, e.g.0.1
.
Optional:
-
size
: The number of pixels to turn on in a row, e.g.3
. Defaults to2
if no size is provided. -
spacing
: The number of pixels to turn off in a row, e.g.6
. Defaults to3
if no size is provided. -
reverse
: Optionally reverses the movement of the animation. Set toTrue
to enable. Defaults toFalse
. -
step
: The steps to take through the colorwheel (0-255). A step of1
means cycling through the entire colorwheel, a step of2
means it cycles through every other possible value. Defaults to8
if no step is provided.
Once created, you display the animation.
rainbow_chase = RainbowChase(pixels, speed=0.1, size=5, spacing=3) while True: rainbow_chase.animate()
That's all there is to displaying a rainbow theatre chase animation using the LED Animation library! Let's take a look at the next animation.
RainbowComet
This is a rainbow version of a comet of a specified speed, with a dimming tail of specified length.
First, you import the RainbowComet
module. See Import and Setup for the rest of the necessary imports and pixel object creation.
from adafruit_led_animation.animation.rainbowcomet import RainbowComet
Next you create the RainbowComet
animation. RainbowComet
requires two arguments, and has an optional four more. You'll likely want to specify at least tail_length
.
Required:
-
pixel_object
: The pixel object, e.g.pixels
. -
speed
: The speed of the comet in seconds, e.g.0.1
.
Optional:
-
tail_length
: The length of the comet in pixels. Defaults to 25% of the length of thepixel_object
if no length is provided. Automatically compensates for a minimum length of2
and a maximum of the length of thepixel_object
. -
reverse
: Optionally reverses the movement of the animation. Set toTrue
to enable. Defaults toFalse
. -
bounce
: Optionally "bounces" the comet along the strip by displaying it from the beginning of the strip to the end, and then reversing the movement once it reaches the end of the strip. Set toTrue
to enable. Defaults toFalse
. -
colorwheel_offset
: Offset from the start of the colorwheel. Provide a value of0
-255
where0
is red,85
is blue and170
is green, wrapping back to255
being red. Defaults to0
.
Once created, you display the animation.
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=7, bounce=True) while True: rainbow_comet.animate()
RainbowSparkle
This is a shifting rainbow that sparkles.
First, you import the RainbowSparkle
module. See Import and Setup for the rest of the necessary imports and pixel object creation.
from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle
Next you create the RainbowSparkle
animation. RainbowSparkle
requires two arguments, and has an optional five more.
Required:
-
pixel_object
: The pixel object, e.g.pixels
. -
speed
: The refresh rate of the rainbow in seconds, e.g.0.1
.
Optional:
-
period
: The period over which to cycle the rainbow in seconds, e.g.2
. Defaults to 5 if no period is provided. -
num_sparkles
: The number of sparkles. Defaults to 5% of the length of thepixel_object
. -
step
: The steps to take through the colorwheel (0-255). A step of1
means cycling through the entire colorwheel, a step of2
means it cycles through every other possible value. Defaults to1
if no step is provided. -
precompute_rainbow
: Precompute the rainbow which increases its speed, but uses more memory. Set toFalse
to disable if you are running into memory limitations. Defaults toTrue
.
Once created, you display the animation.
rainbow_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=15) while True: rainbow_sparkle.animate()
That's how to display a rainbow sparkle animation using the LED Animation library! Next up: sparkles!
# 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. This example does not work on SAMD21 (M0) boards. """ import board import neopixel from adafruit_led_animation.animation.rainbow import Rainbow from adafruit_led_animation.animation.rainbowchase import RainbowChase from adafruit_led_animation.animation.rainbowcomet import RainbowComet from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle 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) rainbow = Rainbow(pixels, speed=0.1, period=2) rainbow_chase = RainbowChase(pixels, speed=0.1, size=5, spacing=3) rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=7, bounce=True) rainbow_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=15) animations = AnimationSequence( rainbow, rainbow_chase, rainbow_comet, rainbow_sparkle, advance_interval=5, auto_clear=True, ) while True: animations.animate()
Page last edited January 22, 2025
Text editor powered by tinymce.