Skip to content

Commit efa5831

Browse files
authored
Merge pull request #26 from kattni/more-example-updates
Small fixes and add group example.
2 parents 1810c83 + a110ab1 commit efa5831

9 files changed

+105
-13
lines changed

adafruit_led_animation/group.py

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,54 @@
5050

5151
class AnimationGroup:
5252
"""
53-
A group of animations that are active together. An example would be grouping a strip of
54-
pixels connected to a board and the onboard LED.
53+
AnimationGroup synchronizes multiple animations. Allows for multiple animations to be kept in
54+
sync, whether or not the same animation or pixel object is in use.
5555
5656
:param members: The animation objects or groups.
57-
:param bool sync: Synchronises the timing of all members of the group to the settings of the
58-
first member of the group. Defaults to ``False``.
59-
57+
:param bool sync: Synchronises when draw is called for all members of the group to the settings
58+
of the first member of the group. Defaults to ``False``.
59+
60+
61+
Example:
62+
63+
.. code-block::
64+
65+
import board
66+
import neopixel
67+
from adafruit_circuitplayground import cp
68+
from adafruit_led_animation.animation.blink import Blink
69+
from adafruit_led_animation.animation.comet import Comet
70+
from adafruit_led_animation.animation.chase import Chase
71+
from adafruit_led_animation.group import AnimationGroup
72+
from adafruit_led_animation.sequence import AnimationSequence
73+
74+
import adafruit_led_animation.color as color
75+
76+
strip_pixels = neopixel.NeoPixel(board.A1, 30, brightness=0.5, auto_write=False)
77+
cp.pixels.brightness = 0.5
78+
79+
animations = AnimationSequence(
80+
# Synchronized to 0.5 seconds. Ignores the second animation setting of 3 seconds.
81+
AnimationGroup(
82+
Blink(cp.pixels, 0.5, color.CYAN),
83+
Blink(strip_pixels, 3.0, color.AMBER),
84+
sync=True,
85+
),
86+
# Different speeds
87+
AnimationGroup(
88+
Comet(cp.pixels, 0.1, color.MAGENTA, tail_length=5),
89+
Comet(strip_pixels, 0.01, color.MAGENTA, tail_length=15),
90+
),
91+
# Sequential animations on the built-in NeoPixels then the NeoPixel strip
92+
Chase(cp.pixels, 0.05, size=2, spacing=3, color=color.PURPLE),
93+
Chase(strip_pixels, 0.05, size=2, spacing=3, color=color.PURPLE),
94+
advance_interval=3.0,
95+
auto_clear=True,
96+
auto_reset=True,
97+
)
98+
99+
while True:
100+
animations.animate()
60101
"""
61102

62103
def __init__(self, *members, sync=False, name=None):

examples/led_animation_all_animations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# Update to match the number of NeoPixels you have connected
3030
pixel_num = 32
3131

32-
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
32+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
3333

3434
blink = Blink(pixels, speed=0.5, color=JADE)
3535
colorcycle = ColorCycle(pixels, speed=0.4, colors=[MAGENTA, ORANGE])
@@ -41,7 +41,7 @@
4141
rainbow = Rainbow(pixels, speed=0.1, period=2)
4242
sparkle_pulse = SparklePulse(pixels, speed=0.1, period=3, color=JADE)
4343
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=7, bounce=True)
44-
rainbow_chase = RainbowChase(pixels, speed=0.1, size=3, spacing=2, wheel_step=8)
44+
rainbow_chase = RainbowChase(pixels, speed=0.1, size=3, spacing=2, step=8)
4545
rainbow_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=15)
4646

4747

examples/led_animation_basic_animations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# Update to match the number of NeoPixels you have connected
3333
pixel_num = 32
3434

35-
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
35+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
3636

3737
solid = Solid(pixels, color=PINK)
3838
blink = Blink(pixels, speed=0.5, color=JADE)

examples/led_animation_group.py

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

examples/led_animation_pixel_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Update to match the number of NeoPixels you have connected
2626
pixel_num = 32
2727

28-
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
28+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
2929

3030
pixel_wing_vertical = helper.PixelMap.vertical_lines(
3131
pixels, 8, 4, helper.horizontal_strip_gridmap(8, alternating=False)

examples/led_animation_rainbow_animations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Update to match the number of NeoPixels you have connected
2222
pixel_num = 32
2323

24-
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
24+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
2525

2626
rainbow = Rainbow(pixels, speed=0.1, period=2)
2727
rainbow_chase = RainbowChase(pixels, speed=0.1, size=5, spacing=3)

examples/led_animation_sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Update to match the number of NeoPixels you have connected
2020
pixel_num = 32
2121

22-
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.1, auto_write=False)
22+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
2323

2424
blink = Blink(pixels, speed=0.5, color=JADE)
2525
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)

examples/led_animation_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Update to match the number of NeoPixels you have connected
1515
pixel_num = 32
1616

17-
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
17+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
1818

1919
blink = Blink(pixels, speed=0.5, color=RED)
2020

examples/led_animation_sparkle_animations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Update to match the number of NeoPixels you have connected
1919
pixel_num = 32
2020

21-
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
21+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
2222

2323
sparkle = Sparkle(pixels, speed=0.05, color=AMBER, num_sparkles=10)
2424
sparkle_pulse = SparklePulse(pixels, speed=0.05, period=3, color=JADE)

0 commit comments

Comments
 (0)