From a90235b31a43a851c72fe142255c289fcedb251e Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 11:57:58 -0400 Subject: [PATCH 1/9] Add tail_length exception, update example imports. --- adafruit_led_animation/animation/comet.py | 11 ++++- examples/led_animation_all_animations.py | 60 +++++++++-------------- examples/led_animation_gridmap.py | 30 +++++------- examples/led_animation_simpletest.py | 10 ++-- 4 files changed, 50 insertions(+), 61 deletions(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 4476128..00d5e11 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -57,7 +57,12 @@ class Comet(Animation): :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. :param int tail_length: The length of the comet. Defaults to 10. Cannot exceed the number of pixels present in the pixel object, e.g. if the strip is 30 pixels - long, the ``tail_length`` cannot exceed 30 pixels. + long, the ``tail_length`` cannot exceed 30 pixels, or, in the case of a + pixel mapped grid, if the width of the grid is 13 pixels, a horizontal + comet tail cannot exceed 13 pixels. To find the lenth of the + ``pixel_object``, include a ``print(len(PIXEL_OBJECT_NAME))`` in your + code anywhere after the object creation, where ``PIXEL_OBJECT_NAME`` is + the name assigned to the object, such as ``pixels``. :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``. :param bool bounce: Comet will bounce back and forth. Defaults to ``True``. """ @@ -73,6 +78,10 @@ def __init__( bounce=False, name=None, ): + if tail_length > len(pixel_object): + raise ValueError( + "Tail length must be less than the length of the pixel_object." + ) self._tail_length = tail_length + 1 self._color_step = 0.9 / tail_length self._color_offset = 0.1 diff --git a/examples/led_animation_all_animations.py b/examples/led_animation_all_animations.py index 954ff69..4c644d3 100644 --- a/examples/led_animation_all_animations.py +++ b/examples/led_animation_all_animations.py @@ -9,18 +9,18 @@ import board import neopixel -import adafruit_led_animation.animation.blink as blink_animation -import adafruit_led_animation.animation.sparklepulse as sparklepulse_animation -import adafruit_led_animation.animation.comet as comet_animation -import adafruit_led_animation.animation.chase as chase_animation -import adafruit_led_animation.animation.pulse as pulse_animation -import adafruit_led_animation.animation.sparkle as sparkle_animation -import adafruit_led_animation.animation.rainbowchase as rainbowchase_animation -import adafruit_led_animation.animation.rainbowsparkle as rainbowsparkle_animation -import adafruit_led_animation.animation.rainbowcomet as rainbowcomet_animation -import adafruit_led_animation.animation.solid as solid_animation -import adafruit_led_animation.animation.colorcycle as colorcycle_animation -import adafruit_led_animation.animation.rainbow as rainbow_animation +from adafruit_led_animation.animation.blink import Blink +from adafruit_led_animation.animation.sparklepulse import SparklePulse +from adafruit_led_animation.animation.comet import Comet +from adafruit_led_animation.animation.chase import Chase +from adafruit_led_animation.animation.pulse import Pulse +from adafruit_led_animation.animation.sparkle import Sparkle +from adafruit_led_animation.animation.rainbowchase import RainbowChase +from adafruit_led_animation.animation.rainbowsparkle import RainbowSparkle +from adafruit_led_animation.animation.rainbowcomet import RainbowComet +from adafruit_led_animation.animation.solid import Solid +from adafruit_led_animation.animation.colorcycle import ColorCycle +from adafruit_led_animation.animation.rainbow import Rainbow from adafruit_led_animation.sequence import AnimationSequence from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE, MAGENTA, ORANGE @@ -31,30 +31,18 @@ pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False) -blink = blink_animation.Blink(pixels, speed=0.5, color=JADE) -colorcycle = colorcycle_animation.ColorCycle( - pixels, speed=0.4, colors=[MAGENTA, ORANGE] -) -comet = comet_animation.Comet( - pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True -) -chase = chase_animation.Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE) -pulse = pulse_animation.Pulse(pixels, speed=0.1, period=3, color=AMBER) -sparkle = sparkle_animation.Sparkle(pixels, speed=0.1, color=PURPLE, num_sparkles=10) -solid = solid_animation.Solid(pixels, color=JADE) -rainbow = rainbow_animation.Rainbow(pixels, speed=0.1, period=2) -sparkle_pulse = sparklepulse_animation.SparklePulse( - pixels, speed=0.1, period=3, color=JADE -) -rainbow_comet = rainbowcomet_animation.RainbowComet( - pixels, speed=0.1, tail_length=7, bounce=True -) -rainbow_chase = rainbowchase_animation.RainbowChase( - pixels, speed=0.1, size=3, spacing=2, wheel_step=8 -) -rainbow_sparkle = rainbowsparkle_animation.RainbowSparkle( - pixels, speed=0.1, num_sparkles=15 -) +blink = Blink(pixels, speed=0.5, color=JADE) +colorcycle = ColorCycle(pixels, speed=0.4, colors=[MAGENTA, ORANGE]) +comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True) +chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE) +pulse = Pulse(pixels, speed=0.1, period=3, color=AMBER) +sparkle = Sparkle(pixels, speed=0.1, color=PURPLE, num_sparkles=10) +solid = Solid(pixels, color=JADE) +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_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=15) animations = AnimationSequence( diff --git a/examples/led_animation_gridmap.py b/examples/led_animation_gridmap.py index d696751..0d1de28 100644 --- a/examples/led_animation_gridmap.py +++ b/examples/led_animation_gridmap.py @@ -10,11 +10,11 @@ import board import neopixel -import adafruit_led_animation.animation.comet as comet_animation -import adafruit_led_animation.animation.rainbowcomet as rainbowcomet_animation -import adafruit_led_animation.animation.rainbowchase as rainbowchase_animation -import adafruit_led_animation.animation.chase as chase_animation -import adafruit_led_animation.animation.rainbow as rainbow_animation +from adafruit_led_animation.animation.comet import Comet +from adafruit_led_animation.animation.rainbowcomet import RainbowComet +from adafruit_led_animation.animation.rainbowchase import RainbowChase +from adafruit_led_animation.animation.chase import Chase +from adafruit_led_animation.animation.rainbow import Rainbow from adafruit_led_animation.sequence import AnimationSequence from adafruit_led_animation import helper from adafruit_led_animation.color import PURPLE, JADE, AMBER @@ -29,25 +29,19 @@ pixels, 8, 4, helper.horizontal_strip_gridmap(8, alternating=False) ) -comet_h = comet_animation.Comet( +comet_h = Comet( pixel_wing_horizontal, speed=0.1, color=PURPLE, tail_length=3, bounce=True ) -comet_v = comet_animation.Comet( - pixel_wing_vertical, speed=0.1, color=AMBER, tail_length=6, bounce=True -) -chase_h = chase_animation.Chase( - pixel_wing_horizontal, speed=0.1, size=3, spacing=6, color=JADE -) -rainbow_chase_v = rainbowchase_animation.RainbowChase( +comet_v = Comet(pixel_wing_vertical, speed=0.1, color=AMBER, tail_length=6, bounce=True) +chase_h = Chase(pixel_wing_horizontal, speed=0.1, size=3, spacing=6, color=JADE) +rainbow_chase_v = RainbowChase( pixel_wing_vertical, speed=0.1, size=3, spacing=2, wheel_step=8 ) -rainbow_comet_v = rainbowcomet_animation.RainbowComet( +rainbow_comet_v = RainbowComet( pixel_wing_vertical, speed=0.1, tail_length=7, bounce=True ) -rainbow_v = rainbow_animation.Rainbow(pixel_wing_vertical, speed=0.1, period=2) -rainbow_chase_h = rainbowchase_animation.RainbowChase( - pixel_wing_horizontal, speed=0.1, size=3, spacing=3 -) +rainbow_v = Rainbow(pixel_wing_vertical, speed=0.1, period=2) +rainbow_chase_h = RainbowChase(pixel_wing_horizontal, speed=0.1, size=3, spacing=3) animations = AnimationSequence( rainbow_v, diff --git a/examples/led_animation_simpletest.py b/examples/led_animation_simpletest.py index 686b7f8..ca324c3 100644 --- a/examples/led_animation_simpletest.py +++ b/examples/led_animation_simpletest.py @@ -9,8 +9,8 @@ """ import board import neopixel -import adafruit_led_animation.animation.comet as comet_animation -import adafruit_led_animation.animation.chase as chase_animation +from adafruit_led_animation.animation.comet import Comet +from adafruit_led_animation.animation.chase import Chase from adafruit_led_animation.sequence import AnimationSequence from adafruit_led_animation.color import PURPLE, WHITE @@ -21,10 +21,8 @@ pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False) -comet = comet_animation.Comet( - pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True -) -chase = chase_animation.Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE) +comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True) +chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE) animations = AnimationSequence(comet, chase, advance_interval=5) From 5d4e1616422e2c76e0793c157d7ecb739a535047 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 12:47:20 -0400 Subject: [PATCH 2/9] Make simpletest simpler. --- examples/led_animation_simpletest.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/examples/led_animation_simpletest.py b/examples/led_animation_simpletest.py index ca324c3..3879e62 100644 --- a/examples/led_animation_simpletest.py +++ b/examples/led_animation_simpletest.py @@ -1,18 +1,13 @@ """ -This simpletest example repeatedly displays two animations, Comet and Chase, at a five second -interval. +This simpletest example displays the Blink animation. For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using a different form of NeoPixels. - -This example does not work on SAMD21 (M0) boards. """ import board import neopixel -from adafruit_led_animation.animation.comet import Comet -from adafruit_led_animation.animation.chase import Chase -from adafruit_led_animation.sequence import AnimationSequence -from adafruit_led_animation.color import PURPLE, WHITE +from adafruit_led_animation.animation.blink import Blink +from adafruit_led_animation.color import RED # Update to match the pin connected to your NeoPixels pixel_pin = board.D6 @@ -21,10 +16,7 @@ pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.2, auto_write=False) -comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True) -chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE) - -animations = AnimationSequence(comet, chase, advance_interval=5) +blink = Blink(pixels, speed=0.5, color=RED) while True: - animations.animate() + blink.animate() From fa7bb0f46e0c823a8dd89365c409691cf6be1c71 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 13:01:25 -0400 Subject: [PATCH 3/9] Add AnimationSequence example. --- examples/led_animation_sequence.py | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/led_animation_sequence.py diff --git a/examples/led_animation_sequence.py b/examples/led_animation_sequence.py new file mode 100644 index 0000000..8b2bb0d --- /dev/null +++ b/examples/led_animation_sequence.py @@ -0,0 +1,38 @@ +""" +This example uses AnimationsSequence to display multiple animations in sequence, at a five second +interval. + +For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using +a different form of NeoPixels. + +This example does not work on SAMD21 (M0) boards. +""" +import board +import neopixel + +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.animation.pulse import Pulse +from adafruit_led_animation.sequence import AnimationSequence +from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE + +# Update to match the pin connected to your NeoPixels +pixel_pin = board.D6 +# 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) + +blink = Blink(pixels, speed=0.5, color=JADE) +comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True) +chase = Chase(pixels, speed=0.1, size=3, spacing=6, color=WHITE) +pulse = Pulse(pixels, speed=0.1, period=3, color=AMBER) + + +animations = AnimationSequence( + comet, blink, chase, pulse, advance_interval=5, auto_clear=True, +) + +while True: + animations.animate() From 4240a4b44569b51f9cb8134346b49040f6ca836b Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 13:20:12 -0400 Subject: [PATCH 4/9] Default to auto_clear --- adafruit_led_animation/sequence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/sequence.py b/adafruit_led_animation/sequence.py index c64f54b..0725955 100644 --- a/adafruit_led_animation/sequence.py +++ b/adafruit_led_animation/sequence.py @@ -96,7 +96,7 @@ def __init__( self, *members, advance_interval=None, - auto_clear=False, + auto_clear=True, random_order=False, auto_reset=False, advance_on_cycle_complete=False, From 3aa735a44414c3ae835a8d639e9c8a7e3cc934f7 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 13:41:55 -0400 Subject: [PATCH 5/9] Update to have min/max tail length automatically. --- adafruit_led_animation/animation/comet.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 00d5e11..0f3a7e8 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -73,16 +73,16 @@ def __init__( pixel_object, speed, color, - tail_length=10, + tail_length=None, reverse=False, bounce=False, name=None, ): - if tail_length > len(pixel_object): - raise ValueError( - "Tail length must be less than the length of the pixel_object." - ) - self._tail_length = tail_length + 1 + if tail_length is None: + tail_length = int(len(pixel_object) / 4) + else: + tail_length = max(2, min(tail_length, len(pixel_object))) + self._tail_length = tail_length self._color_step = 0.9 / tail_length self._color_offset = 0.1 self._comet_colors = None From 87c1f17d4d4ab86b43cac675992503963311943f Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 13:49:39 -0400 Subject: [PATCH 6/9] Use integer division --- adafruit_led_animation/animation/comet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 0f3a7e8..40298d9 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -79,7 +79,7 @@ def __init__( name=None, ): if tail_length is None: - tail_length = int(len(pixel_object) / 4) + tail_length = len(pixel_object) // 4 else: tail_length = max(2, min(tail_length, len(pixel_object))) self._tail_length = tail_length From 2248b4f275fb6a9accb38416eb7e05bf97af366c Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 13:55:09 -0400 Subject: [PATCH 7/9] Update tail length documentation. --- adafruit_led_animation/animation/comet.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 40298d9..0742f00 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -55,14 +55,9 @@ class Comet(Animation): :param pixel_object: The initialised LED object. :param float speed: Animation speed in seconds, e.g. ``0.1``. :param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format. - :param int tail_length: The length of the comet. Defaults to 10. Cannot exceed the number of - pixels present in the pixel object, e.g. if the strip is 30 pixels - long, the ``tail_length`` cannot exceed 30 pixels, or, in the case of a - pixel mapped grid, if the width of the grid is 13 pixels, a horizontal - comet tail cannot exceed 13 pixels. To find the lenth of the - ``pixel_object``, include a ``print(len(PIXEL_OBJECT_NAME))`` in your - code anywhere after the object creation, where ``PIXEL_OBJECT_NAME`` is - the name assigned to the object, such as ``pixels``. + :param int tail_length: The length of the comet. Defaults to 25% of the length of the + ``pixel_object``. Automatically compensates for a minimum of 2 and a + maximum of the length of the ``pixel_object``. :param bool reverse: Animates the comet in the reverse order. Defaults to ``False``. :param bool bounce: Comet will bounce back and forth. Defaults to ``True``. """ From 5b4b9c85ebdc82013dd04e15bb001a10175d166d Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 15:01:17 -0400 Subject: [PATCH 8/9] Workaround Pylint bug. --- adafruit_led_animation/animation/comet.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 0742f00..06986d5 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -68,12 +68,12 @@ def __init__( pixel_object, speed, color, - tail_length=None, + tail_length=0, reverse=False, bounce=False, name=None, ): - if tail_length is None: + if tail_length is 0: tail_length = len(pixel_object) // 4 else: tail_length = max(2, min(tail_length, len(pixel_object))) From c7d1950476c346f8435c75e5e07fb81dd1606078 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 18 May 2020 15:05:31 -0400 Subject: [PATCH 9/9] is to --. --- adafruit_led_animation/animation/comet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_led_animation/animation/comet.py b/adafruit_led_animation/animation/comet.py index 06986d5..3ea28a3 100644 --- a/adafruit_led_animation/animation/comet.py +++ b/adafruit_led_animation/animation/comet.py @@ -73,7 +73,7 @@ def __init__( bounce=False, name=None, ): - if tail_length is 0: + if tail_length == 0: tail_length = len(pixel_object) // 4 else: tail_length = max(2, min(tail_length, len(pixel_object)))