Skip to content

Small fixes and add group example. #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions adafruit_led_animation/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,54 @@

class AnimationGroup:
"""
A group of animations that are active together. An example would be grouping a strip of
pixels connected to a board and the onboard LED.
AnimationGroup synchronizes multiple animations. Allows for multiple animations to be kept in
sync, whether or not the same animation or pixel object is in use.

:param members: The animation objects or groups.
:param bool sync: Synchronises the timing of all members of the group to the settings of the
first member of the group. Defaults to ``False``.

:param bool sync: Synchronises when draw is called for all members of the group to the settings
of the first member of the group. Defaults to ``False``.


Example:

.. code-block::

import board
import neopixel
from adafruit_circuitplayground import cp
from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.group import AnimationGroup
from adafruit_led_animation.sequence import AnimationSequence

import adafruit_led_animation.color as color

strip_pixels = neopixel.NeoPixel(board.A1, 30, brightness=0.5, auto_write=False)
cp.pixels.brightness = 0.5

animations = AnimationSequence(
# Synchronized to 0.5 seconds. Ignores the second animation setting of 3 seconds.
AnimationGroup(
Blink(cp.pixels, 0.5, color.CYAN),
Blink(strip_pixels, 3.0, color.AMBER),
sync=True,
),
# Different speeds
AnimationGroup(
Comet(cp.pixels, 0.1, color.MAGENTA, tail_length=5),
Comet(strip_pixels, 0.01, color.MAGENTA, tail_length=15),
),
# Sequential animations on the built-in NeoPixels then the NeoPixel strip
Chase(cp.pixels, 0.05, size=2, spacing=3, color=color.PURPLE),
Chase(strip_pixels, 0.05, size=2, spacing=3, color=color.PURPLE),
advance_interval=3.0,
auto_clear=True,
auto_reset=True,
)

while True:
animations.animate()
"""

def __init__(self, *members, sync=False, name=None):
Expand Down
4 changes: 2 additions & 2 deletions examples/led_animation_all_animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Update to match the number of NeoPixels you have connected
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

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


Expand Down
2 changes: 1 addition & 1 deletion examples/led_animation_basic_animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# Update to match the number of NeoPixels you have connected
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

solid = Solid(pixels, color=PINK)
blink = Blink(pixels, speed=0.5, color=JADE)
Expand Down
51 changes: 51 additions & 0 deletions examples/led_animation_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
This example shows three different ways to use AnimationGroup: syncing two animations, displaying
two animations at different speeds, and displaying two animations sequentially, across two separate
pixel objects such as the built-in NeoPixels on a Circuit Playground Bluefruit and a NeoPixel strip.

This example is written for Circuit Playground Bluefruit and a 30-pixel NeoPixel strip connected to
pad A1. It does not work on Circuit Playground Express.
"""
import board
import neopixel
from adafruit_circuitplayground import cp

from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.animation.chase import Chase

from adafruit_led_animation.group import AnimationGroup
from adafruit_led_animation.sequence import AnimationSequence

import adafruit_led_animation.color as color

strip_pixels = neopixel.NeoPixel(board.A1, 30, brightness=0.5, auto_write=False)
cp.pixels.brightness = 0.5

animations = AnimationSequence(
# Synchronized to 0.5 seconds. Ignores the second animation setting of 3 seconds.
AnimationGroup(
Blink(cp.pixels, 0.5, color.CYAN),
Blink(strip_pixels, 3.0, color.AMBER),
sync=True,
),
# Different speeds
AnimationGroup(
Comet(cp.pixels, 0.1, color.MAGENTA, tail_length=5),
Comet(strip_pixels, 0.01, color.MAGENTA, tail_length=15),
),
# Different animations
AnimationGroup(
Blink(cp.pixels, 0.5, color.JADE),
Comet(strip_pixels, 0.05, color.TEAL, tail_length=15),
),
# Sequential animations on the built-in NeoPixels then the NeoPixel strip
Chase(cp.pixels, 0.05, size=2, spacing=3, color=color.PURPLE),
Chase(strip_pixels, 0.05, size=2, spacing=3, color=color.PURPLE),
advance_interval=3.0,
auto_clear=True,
auto_reset=True,
)

while True:
animations.animate()
2 changes: 1 addition & 1 deletion examples/led_animation_pixel_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Update to match the number of NeoPixels you have connected
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

pixel_wing_vertical = helper.PixelMap.vertical_lines(
pixels, 8, 4, helper.horizontal_strip_gridmap(8, alternating=False)
Expand Down
2 changes: 1 addition & 1 deletion examples/led_animation_rainbow_animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Update to match the number of NeoPixels you have connected
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

rainbow = Rainbow(pixels, speed=0.1, period=2)
rainbow_chase = RainbowChase(pixels, speed=0.1, size=5, spacing=3)
Expand Down
2 changes: 1 addition & 1 deletion examples/led_animation_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Update to match the number of NeoPixels you have connected
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.1, auto_write=False)
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

blink = Blink(pixels, speed=0.5, color=JADE)
comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/led_animation_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Update to match the number of NeoPixels you have connected
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

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

Expand Down
2 changes: 1 addition & 1 deletion examples/led_animation_sparkle_animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Update to match the number of NeoPixels you have connected
pixel_num = 32

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False)
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)

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