/ examples / led_animation_group.py
led_animation_group.py
 1  # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 3  # SPDX-License-Identifier: MIT
 4  
 5  """
 6  This example shows three different ways to use AnimationGroup: syncing two animations, displaying
 7  two animations at different speeds, and displaying two animations sequentially, across two separate
 8  pixel objects such as the built-in NeoPixels on a Circuit Playground Bluefruit and a NeoPixel strip.
 9  
10  This example is written for Circuit Playground Bluefruit and a 30-pixel NeoPixel strip connected to
11  pad A1. It does not work on Circuit Playground Express.
12  """
13  import board
14  import neopixel
15  from adafruit_circuitplayground import cp
16  
17  from adafruit_led_animation.animation.blink import Blink
18  from adafruit_led_animation.animation.comet import Comet
19  from adafruit_led_animation.animation.chase import Chase
20  
21  from adafruit_led_animation.group import AnimationGroup
22  from adafruit_led_animation.sequence import AnimationSequence
23  
24  import adafruit_led_animation.color as color
25  
26  strip_pixels = neopixel.NeoPixel(board.A1, 30, brightness=0.5, auto_write=False)
27  cp.pixels.brightness = 0.5
28  
29  animations = AnimationSequence(
30      # Synchronized to 0.5 seconds. Ignores the second animation setting of 3 seconds.
31      AnimationGroup(
32          Blink(cp.pixels, 0.5, color.CYAN),
33          Blink(strip_pixels, 3.0, color.AMBER),
34          sync=True,
35      ),
36      # Different speeds
37      AnimationGroup(
38          Comet(cp.pixels, 0.1, color.MAGENTA, tail_length=5),
39          Comet(strip_pixels, 0.01, color.MAGENTA, tail_length=15),
40      ),
41      # Different animations
42      AnimationGroup(
43          Blink(cp.pixels, 0.5, color.JADE),
44          Comet(strip_pixels, 0.05, color.TEAL, tail_length=15),
45      ),
46      # Sequential animations on the built-in NeoPixels then the NeoPixel strip
47      Chase(cp.pixels, 0.05, size=2, spacing=3, color=color.PURPLE),
48      Chase(strip_pixels, 0.05, size=2, spacing=3, color=color.PURPLE),
49      advance_interval=3.0,
50      auto_clear=True,
51      auto_reset=True,
52  )
53  
54  while True:
55      animations.animate()