From a110ab1a7a566f3f5a1ed66749eaceecc864b9ce Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Sun, 24 May 2020 17:08:20 -0400 Subject: [PATCH] Small fixes and add group example. --- adafruit_led_animation/group.py | 51 ++++++++++++++++++-- examples/led_animation_all_animations.py | 4 +- examples/led_animation_basic_animations.py | 2 +- examples/led_animation_group.py | 51 ++++++++++++++++++++ examples/led_animation_pixel_map.py | 2 +- examples/led_animation_rainbow_animations.py | 2 +- examples/led_animation_sequence.py | 2 +- examples/led_animation_simpletest.py | 2 +- examples/led_animation_sparkle_animations.py | 2 +- 9 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 examples/led_animation_group.py diff --git a/adafruit_led_animation/group.py b/adafruit_led_animation/group.py index 769d5e4..a9dacb9 100644 --- a/adafruit_led_animation/group.py +++ b/adafruit_led_animation/group.py @@ -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): diff --git a/examples/led_animation_all_animations.py b/examples/led_animation_all_animations.py index 4c644d3..16a82bd 100644 --- a/examples/led_animation_all_animations.py +++ b/examples/led_animation_all_animations.py @@ -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]) @@ -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) diff --git a/examples/led_animation_basic_animations.py b/examples/led_animation_basic_animations.py index 551957f..b4139c7 100644 --- a/examples/led_animation_basic_animations.py +++ b/examples/led_animation_basic_animations.py @@ -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) diff --git a/examples/led_animation_group.py b/examples/led_animation_group.py new file mode 100644 index 0000000..a0676ed --- /dev/null +++ b/examples/led_animation_group.py @@ -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() diff --git a/examples/led_animation_pixel_map.py b/examples/led_animation_pixel_map.py index 6dd2a93..565f19a 100644 --- a/examples/led_animation_pixel_map.py +++ b/examples/led_animation_pixel_map.py @@ -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) diff --git a/examples/led_animation_rainbow_animations.py b/examples/led_animation_rainbow_animations.py index 27e5441..0dc378a 100644 --- a/examples/led_animation_rainbow_animations.py +++ b/examples/led_animation_rainbow_animations.py @@ -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) diff --git a/examples/led_animation_sequence.py b/examples/led_animation_sequence.py index 4f1bd3d..fd4fba5 100644 --- a/examples/led_animation_sequence.py +++ b/examples/led_animation_sequence.py @@ -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) diff --git a/examples/led_animation_simpletest.py b/examples/led_animation_simpletest.py index 3879e62..94f7f06 100644 --- a/examples/led_animation_simpletest.py +++ b/examples/led_animation_simpletest.py @@ -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) diff --git a/examples/led_animation_sparkle_animations.py b/examples/led_animation_sparkle_animations.py index f8c633f..ad90292 100644 --- a/examples/led_animation_sparkle_animations.py +++ b/examples/led_animation_sparkle_animations.py @@ -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)