/ examples / led_animation_customcolorchase.py
led_animation_customcolorchase.py
 1  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 2  # SPDX-License-Identifier: MIT
 3  
 4  """
 5  This example displays custom color chase animations in sequence, at a six second interval.
 6  
 7  For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
 8  a different form of NeoPixels.
 9  
10  This example may not work on SAMD21 (M0) boards.
11  """
12  import board
13  import neopixel
14  
15  from adafruit_led_animation.animation.customcolorchase import CustomColorChase
16  from adafruit_led_animation.sequence import AnimationSequence
17  
18  # colorwheel only needed for rainbowchase example
19  from adafruit_led_animation.color import colorwheel
20  
21  # Colors for customcolorchase examples
22  from adafruit_led_animation.color import PINK, GREEN, RED, BLUE
23  
24  # Update to match the pin connected to your NeoPixels
25  pixel_pin = board.D5
26  # Update to match the number of NeoPixels you have connected
27  pixel_num = 30
28  brightness = 0.3
29  
30  pixels = neopixel.NeoPixel(
31      pixel_pin, pixel_num, brightness=brightness, auto_write=False
32  )
33  
34  # colors default to RAINBOW as defined in color.py
35  custom_color_chase_rainbow = CustomColorChase(pixels, speed=0.1, size=2, spacing=3)
36  custom_color_chase_rainbow_r = CustomColorChase(
37      pixels, speed=0.1, size=3, spacing=3, reverse=True
38  )
39  
40  # Example with same colors as RainbowChase
41  steps = 30
42  # This was taken from rainbowchase.py
43  rainbow_colors = [colorwheel(n % 256) for n in range(0, 512, steps)]
44  # Now use rainbow_colors with CustomColorChase
45  custom_color_chase_rainbowchase = CustomColorChase(
46      pixels, speed=0.1, colors=rainbow_colors, size=2, spacing=3
47  )
48  
49  custom_color_chase_bgp = CustomColorChase(
50      pixels, speed=0.1, colors=[BLUE, GREEN, PINK], size=3, spacing=2
51  )
52  
53  # Can use integer values for color, 0 is black
54  custom_color_chase_br = CustomColorChase(
55      pixels, speed=0.1, colors=[BLUE, 0, RED, 0], size=2, spacing=0
56  )
57  
58  animations = AnimationSequence(
59      custom_color_chase_rainbow,
60      custom_color_chase_rainbow_r,
61      custom_color_chase_rainbowchase,
62      custom_color_chase_bgp,
63      custom_color_chase_br,
64      advance_interval=6,
65      auto_clear=True,
66  )
67  
68  while True:
69      animations.animate()