The LED Animation library has a color
module to make assigning LED colors much simpler. In this module, the RGB value for a color is assigned to a color name variable. In your code, simply import the colors you'd like to use from the module, such as RED
or BLUE
, and then use them anywhere you would use an RGB tuple, e.g. (r, g, b)
.
The current complete list of colors can be found in the color module documentation. Available colors include:
RED
YELLOW
ORANGE
GREEN
TEAL
CYAN
BLUE
PURPLE
MAGENTA
WHITE
BLACK
GOLD
PINK
AQUA
JADE
AMBER
OLD_LACE
To see the RGB value for each color name, check the documentation.
Usage
Using the colors with the LED Animation library is easy. Simply import the colors you want to use, and then include them anywhere you would use an RGB value.
This example uses red.
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries # SPDX-License-Identifier: MIT """ This simpletest example displays the Blink animation. 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.color import RED # 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=RED) while True: blink.animate()
Included at the top is the following line:
from adafruit_led_animation.color import RED
Then, when the animation is set up, instead of using (255, 0, 0)
, you can use RED
.
blink = Blink(pixels, speed=0.5, color=RED)
You can import more than one color at the same time as well. This example uses purple, amber and jade.
# 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()
Included at the top is a similar import line, but this time, there are multiple color names, separated by commas.
from adafruit_led_animation.color import PURPLE, AMBER, JADE
Then each color is used in various places later in the code.
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)
Page last edited January 22, 2025
Text editor powered by tinymce.