The LED Animation library does not work with the base QT Py board. You MUST solder a flash chip to the bottom of your QT Py to create a QT Py Haxpress to use the LED Animation library. This section assumes you have soldered a flash chip to your QT Py and loaded the appropriate version of CircuitPython: https://learn.adafruit.com/adafruit-qt-py/circuitpython

The CircuitPython LED Animation library makes animating your LEDs super simple with a wide variety of easily customisable animations. Most of the available animations run on the SAMD21 microcontroller found on the QT Py. This page provides examples of using blink, chase and comet animations. You can use any of the other valid animations in the same way.

For more details about these animations and the others available in the LED Animation library, check out the CircuitPython LED Animations guide.

CircuitPython LED Animation Library Installation

You'll need to install the Adafruit CircuitPython LED Animation library and the NeoPixel library on your QT Py.

For more details on getting started with this library, check out the Import and Setup page of the CircuitPython LED Animations guide.

First make sure you are running the latest version of Adafruit CircuitPython for the QT Py Haxpress.

Next you'll need to install the necessary libraries to use the LEDs -- carefully follow the steps to find and install these libraries from Adafruit's CircuitPython Library Bundle.  Our CircuitPython starter guide has a great page on how to install libraries from the bundle.

You'll want to manually install the following libraries by copying the files and folders to the lib folder on your CIRCUITPY drive:

  • adafruit_led_animation
  • neopixel.mpy

Before continuing make sure your board's lib folder or root filesystem has the adafruit_led_animation, and neopixel.mpy files and folders copied over.

Blink

This is a blinking animation that lights up and turns off all the LEDs at a specified interval.

Save the following example as code.py on your CIRCUITPY drive:

"""
This example blinks the LEDs purple at a 0.5 second interval.

For QT Py Haxpress and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if
using a different board or form of NeoPixels.

This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
"""
import board
import neopixel

from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.color import PURPLE

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

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

blink = Blink(pixels, speed=0.5, color=PURPLE)

while True:
    blink.animate()

The LEDs should begin to blink purple!

For details on how to customise the blink animation, check out the Blink section of the CircuitPython LED Animations guide.

Chase

This is a theatre chase style animation that lights up blocks of LEDs evenly spaced and chases them along the strip.

Save the following example as code.py on your CIRCUITPY drive:

"""
This example animates a theatre chase style animation in white with a repeated 3 LEDs lit up at a
spacing of six LEDs off.

For QT Py Haxpress and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if
using a different board or form of NeoPixels.

This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
"""
import board
import neopixel

from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.color import WHITE

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

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

chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)

while True:
    chase.animate()

Groups of three LEDs lit up white should chase along the strip spaced out by six LEDs turned off!

For details on how to customise the chase animation, check out the Chase section of the CircuitPython LED Animations guide.

Comet

This is a comet animation with a bright LED moving along the strip with a progressively dimming tail of a specified size following it.

Save the following example as code.py on your CIRCUITPY drive:

"""
This example animates a jade comet that bounces from end to end of the strip.

For QT Py Haxpress and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if
using a different board or form of NeoPixels.

This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
"""
import board
import neopixel

from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.color import JADE

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

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

comet = Comet(pixels, speed=0.02, color=JADE, tail_length=10, bounce=True)

while True:
    comet.animate()

A jade colored comet should begin bouncing back and forth across the strip!

For details on how to customise the comet animation, check out the Comet section of the CircuitPython LED Animations guide.

More Animations

The CircuitPython LED Animation library has many more animations available, most of which will work on your QT Py Haxpress. For more information on the rest of the features of the LED Animation library, check out the CircuitPython LED Animations guide.

This guide was first published on Oct 14, 2020. It was last updated on 2020-10-14 13:46:45 -0400.
This page (LED Animations with QT Py Haxpress) was last updated on Oct 24, 2020.