/ examples / led_animation_pixel_map.py
led_animation_pixel_map.py
 1  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 2  # SPDX-License-Identifier: MIT
 3  
 4  """
 5  This example shows usage of the PixelMap helper to easily treat a single strip as a horizontal or
 6  vertical grid for animation purposes.
 7  
 8  For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
 9  a different form of NeoPixels. Note that if you are using a number of pixels other than 32, you
10  will need to alter the PixelMap values as well for this example to work.
11  
12  This example does not work on SAMD21 (M0) boards.
13  """
14  import board
15  import neopixel
16  
17  from adafruit_led_animation.animation.comet import Comet
18  from adafruit_led_animation.animation.rainbowcomet import RainbowComet
19  from adafruit_led_animation.animation.rainbowchase import RainbowChase
20  from adafruit_led_animation.animation.chase import Chase
21  from adafruit_led_animation.animation.rainbow import Rainbow
22  from adafruit_led_animation.sequence import AnimationSequence
23  from adafruit_led_animation import helper
24  from adafruit_led_animation.color import PURPLE, JADE, AMBER
25  
26  # Update to match the pin connected to your NeoPixels
27  pixel_pin = board.D6
28  # Update to match the number of NeoPixels you have connected
29  pixel_num = 32
30  
31  pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
32  
33  pixel_wing_vertical = helper.PixelMap.vertical_lines(
34      pixels, 8, 4, helper.horizontal_strip_gridmap(8, alternating=False)
35  )
36  pixel_wing_horizontal = helper.PixelMap.horizontal_lines(
37      pixels, 8, 4, helper.horizontal_strip_gridmap(8, alternating=False)
38  )
39  
40  comet_h = Comet(
41      pixel_wing_horizontal, speed=0.1, color=PURPLE, tail_length=3, bounce=True
42  )
43  comet_v = Comet(pixel_wing_vertical, speed=0.1, color=AMBER, tail_length=6, bounce=True)
44  chase_h = Chase(pixel_wing_horizontal, speed=0.1, size=3, spacing=6, color=JADE)
45  rainbow_chase_v = RainbowChase(
46      pixel_wing_vertical, speed=0.1, size=3, spacing=2, step=8
47  )
48  rainbow_comet_v = RainbowComet(
49      pixel_wing_vertical, speed=0.1, tail_length=7, bounce=True
50  )
51  rainbow_v = Rainbow(pixel_wing_vertical, speed=0.1, period=2)
52  rainbow_chase_h = RainbowChase(pixel_wing_horizontal, speed=0.1, size=3, spacing=3)
53  
54  animations = AnimationSequence(
55      rainbow_v,
56      comet_h,
57      rainbow_comet_v,
58      chase_h,
59      rainbow_chase_v,
60      comet_v,
61      rainbow_chase_h,
62      advance_interval=5,
63  )
64  
65  while True:
66      animations.animate()