Skip to content

Commit ed4bbf9

Browse files
committed
Examples and docs.
1 parent ee35ea8 commit ed4bbf9

File tree

4 files changed

+134
-10
lines changed

4 files changed

+134
-10
lines changed

adafruit_led_animation/helper.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,42 @@ class PixelMap:
5858
:param iterable pixel_ranges: Pixel ranges (or individual pixels).
5959
:param bool individual_pixels: Whether pixel_ranges are individual pixels.
6060
61+
To use with ranges of pixels:
62+
6163
.. code-block:: python
6264
6365
import board
6466
import neopixel
6567
from adafruit_led_animation.helper import PixelMap
66-
pixels = neopixel.NeoPixel(board.D12, 307, auto_write=False)
68+
pixels = neopixel.NeoPixel(board.D6, 32, auto_write=False)
6769
68-
tree = PixelMap(pixels, [
69-
(0, 21), (21, 48), (48, 71), (71, 93),(93, 115), (115, 135), (135, 153),
70-
(153, 170), (170, 188), (188, 203), (203, 217), (217, 228), (228, 240),
71-
(240, 247), (247, 253), (253, 256), (256, 260), (260, 307)]
72-
)
73-
tree[0] = (255, 255, 0)
74-
tree.show()
70+
pixel_wing_horizontal = PixelMap(pixels, [(0, 8), (8, 16), (16, 24), (24, 32)])
71+
72+
pixel_wing_horizontal[0] = (255, 255, 0)
73+
pixel_wing_horizontal.show()
74+
75+
To use with individual pixels:
76+
77+
.. code-block:: python
78+
79+
import board
80+
import neopixel
81+
from adafruit_led_animation.helper import PixelMap
82+
pixels = neopixel.NeoPixel(board.D6, 32, auto_write=False)
83+
84+
pixel_wing_vertical = PixelMap(pixels, [
85+
(0, 8, 16, 24),
86+
(1, 9, 17, 25),
87+
(2, 10, 18, 26),
88+
(3, 11, 19, 27),
89+
(4, 12, 20, 28),
90+
(5, 13, 21, 29),
91+
(6, 14, 22, 30),
92+
(7, 15, 23, 31),
93+
], individual_pixels=True)
94+
95+
pixel_wing_vertical[0] = (255, 255, 0)
96+
pixel_wing_vertical.show()
7597
7698
"""
7799

@@ -138,6 +160,7 @@ def brightness(self, brightness):
138160
def fill(self, color):
139161
"""
140162
Fill the used pixel ranges with color.
163+
141164
:param color: Color to fill all pixels referenced by this PixelMap definition with.
142165
"""
143166
if self._individual_pixels:
@@ -222,6 +245,7 @@ def horizontal_lines(cls, pixels, width, height, gridmapper):
222245
def vertical_strip_gridmap(height, alternating=True):
223246
"""
224247
Returns a function that determines the pixel number for a grid with strips arranged vertically.
248+
225249
:param height: strip height in pixels
226250
:param alternating: strips alternate directions in a zigzag
227251
:return: mapper(x, y)
@@ -238,6 +262,7 @@ def mapper(x, y):
238262
def horizontal_strip_gridmap(width, alternating=True):
239263
"""
240264
Determines the pixel number for a grid with strips arranged horizontally.
265+
241266
:param width: strip width in pixels
242267
:param alternating: strips alternate directions in a zigzag
243268
:return: mapper(x, y)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
This example repeatedly displays all available animations, at a five second interval.
3+
4+
For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
5+
a different form of NeoPixels.
6+
"""
7+
import board
8+
import neopixel
9+
from adafruit_led_animation.animation import *
10+
from adafruit_led_animation.helper import AnimationSequence
11+
from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE
12+
13+
# Update to match the pin connected to your NeoPixels
14+
pixel_pin = board.D6
15+
# Update to match the number of NeoPixels you have connected
16+
pixel_num = 32
17+
18+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
19+
20+
blink = Blink(pixels, speed=0.1, color=JADE)
21+
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
22+
chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE)
23+
pulse = Pulse(pixels, speed=0.1, period=3, color=AMBER)
24+
sparkle = Sparkle(pixels, speed=0.1, color=PURPLE, num_sparkles=10)
25+
solid = Solid(pixels, color=JADE)
26+
rainbow = Rainbow(pixels, speed=0.1, period=2)
27+
sparkle_pulse = SparklePulse(pixels, speed=0.1, period=3, color=JADE)
28+
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=7, bounce=True)
29+
rainbow_chase = RainbowChase(pixels, speed=0.1, size=3, spacing=2, wheel_step=8)
30+
31+
32+
animations = AnimationSequence(
33+
blink,
34+
comet,
35+
chase,
36+
pulse,
37+
sparkle,
38+
solid,
39+
rainbow,
40+
sparkle_pulse,
41+
rainbow_comet,
42+
rainbow_chase,
43+
advance_interval=5,
44+
auto_clear=True,
45+
)
46+
47+
while True:
48+
animations.animate()

examples/led_animation_gridmap.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
This example shows usage of the gridmap helper to easily treat a single strip as a horizontal or
3+
vertical grid for animation purposes.
4+
5+
For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
6+
a different form of NeoPixels.
7+
"""
8+
import board
9+
import neopixel
10+
from adafruit_led_animation.animation import *
11+
from adafruit_led_animation.helper import *
12+
from adafruit_led_animation.color import PURPLE, JADE, AMBER
13+
14+
15+
pixels = neopixel.NeoPixel(board.D6, 32, brightness=0.2, auto_write=False)
16+
17+
pixel_wing_vertical = PixelMap.vertical_lines(
18+
pixels, 8, 4, horizontal_strip_gridmap(8, alternating=False)
19+
)
20+
pixel_wing_horizontal = PixelMap.horizontal_lines(
21+
pixels, 8, 4, horizontal_strip_gridmap(8, alternating=False)
22+
)
23+
24+
comet_h = Comet(
25+
pixel_wing_horizontal, speed=0.1, color=PURPLE, tail_length=3, bounce=True
26+
)
27+
comet_v = Comet(pixel_wing_vertical, speed=0.1, color=AMBER, tail_length=6, bounce=True)
28+
chase_h = Chase(pixel_wing_horizontal, speed=0.1, size=3, spacing=6, color=JADE)
29+
rainbow_chase_v = RainbowChase(
30+
pixel_wing_vertical, speed=0.1, size=3, spacing=2, wheel_step=8
31+
)
32+
rainbow_comet_v = RainbowComet(
33+
pixel_wing_vertical, speed=0.1, tail_length=7, bounce=True
34+
)
35+
rainbow_v = Rainbow(pixel_wing_vertical, speed=0.1, period=2)
36+
rainbow_chase_h = RainbowChase(pixel_wing_horizontal, speed=0.1, size=3, spacing=3)
37+
38+
animations = AnimationSequence(
39+
rainbow_v,
40+
comet_h,
41+
rainbow_comet_v,
42+
chase_h,
43+
rainbow_chase_v,
44+
comet_v,
45+
rainbow_chase_h,
46+
advance_interval=5,
47+
)
48+
49+
while True:
50+
animations.animate()

examples/led_animation_simpletest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
2-
This example repeatedly displays two animations, Comet and Chase, at a five second interval.
2+
This simpletest example repeatedly displays two animations, Comet and Chase, at a five second
3+
interval.
34
4-
Designed for NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
5+
For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
56
a different form of NeoPixels.
67
"""
78
import board

0 commit comments

Comments
 (0)