Skip to content

Customcolorschase #51

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 20 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from 11 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
85 changes: 85 additions & 0 deletions adafruit_led_animation/animation/customcolorschase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# The MIT License (MIT)
#
# Copyright (c) 2019-2020 Roy Hooper
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
# Copyright (c) 2020 Connie Sieh
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`adafruit_led_animation.animation.rainbowchase`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated to match the module name, e.g. adafruit_led_animation.animation.customcolorchase.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

================================================================================

Rainbow chase animation for CircuitPython helper library for LED animations.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated to describe the module, e.g. Custom color chase animation for CircuitPython helper library for LED animations..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


* Author(s): Roy Hooper, Kattni Rembor, Connie Sieh

Implementation Notes
--------------------

**Hardware:**

* `Adafruit NeoPixels <https://www.adafruit.com/category/168>`_
* `Adafruit DotStars <https://www.adafruit.com/category/885>`_

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads


"""

from adafruit_led_animation.animation.chase import Chase
from adafruit_led_animation.color import RAINBOW


class CustomColorsChase(Chase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class names are typically singular. Please update this to CustomColorChase. This will also require updating all subsequent use of the class name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

"""
Chase pixels in one direction, like a theater marquee with Custom Colors

:param pixel_object: The initialised LED object.
:param float speed: Animation speed rate in seconds, e.g. ``0.1``.
:param colors: Animation colors in list of `(r, g, b)`` tuple, or ``0x000000`` hex format
:param size: Number of pixels to turn on in a row.
:param spacing: Number of pixels to turn off in a row.
:param reverse: Reverse direction of movement.
"""

# pylint: disable=too-many-arguments
def __init__(
self,
pixel_object,
speed,
size=2,
spacing=3,
reverse=False,
name=None,
colors=RAINBOW,
):
self._num_colors = len(colors)
self._colors = colors
self._color_idx = 0
super().__init__(pixel_object, speed, 0, size, spacing, reverse, name)

def bar_color(self, n, pixel_no=0):
return self._colors[self._color_idx - (n % len(self._colors))]

def on_cycle_complete(self):
self._color_idx = (self._color_idx + self._direction) % len(self._colors)
super().on_cycle_complete()
5 changes: 5 additions & 0 deletions examples/led_animation_all_animations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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.animation.customcolorschase import CustomColorsChase
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.color import PURPLE, WHITE, AMBER, JADE, MAGENTA, ORANGE

Expand All @@ -43,6 +44,9 @@
rainbow_comet = RainbowComet(pixels, speed=0.1, tail_length=7, bounce=True)
rainbow_chase = RainbowChase(pixels, speed=0.1, size=3, spacing=2, step=8)
rainbow_sparkle = RainbowSparkle(pixels, speed=0.1, num_sparkles=15)
custom_colors_chase = CustomColorsChase(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call this custom_color_chase to match the class rename. (As well, the class name will need to be updated.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

pixels, speed=0.1, size=2, spacing=3, colors=[ORANGE, WHITE, JADE]
)


animations = AnimationSequence(
Expand All @@ -57,6 +61,7 @@
rainbow_comet,
sparkle_pulse,
rainbow_chase,
custom_colors_chase,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update this to match, e.g. custom_color_chase.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

advance_interval=5,
auto_clear=True,
)
Expand Down
61 changes: 61 additions & 0 deletions examples/led_animation_customcolorschase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
This example displays the basic animations in sequence, at a five second interval.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs to be updated to describe the new example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
a different form of NeoPixels.

This example may not work on SAMD21 (M0) boards.
"""
import board
import neopixel

from adafruit_led_animation.animation.customcolorschase import CustomColorsChase
from adafruit_led_animation.sequence import AnimationSequence
from adafruit_led_animation.color import PINK, PURPLE, GREEN, RED, WHITE, BLUE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PURPLE is not used. If you do not intend to use it, please remove it from the imports.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed


# Update to match the pin connected to your NeoPixels
pixel_pin = board.D5
# Update to match the number of NeoPixels you have connected
pixel_num = 32
brightness = 0.3

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

# colors default to RAINBOW
custom_colors_chase_rainbow = CustomColorsChase(pixels, speed=0.1, size=2, spacing=3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would update this to custom_color_chase_rainbow - removing the s from colors to match the class rename. Same suggestion goes for all instances of custom_colors in this example.

# Patriotic
custom_colors_chase_rwb = CustomColorsChase(
pixels, speed=0.1, colors=[RED, WHITE, BLUE], size=2, spacing=3
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a worldwide community and want everyone to feel welcome and included. Including this color combination under this name limits the scope of the example to the US, and could create a situation where users from elsewhere in the world, or even in the US, feel excluded. In light of the current climate, I feel it should be removed altogether.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

# St Pat Day
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Associating these color combinations with holidays could be exclusionary as some do not celebrate them. The colors are fine, but please remove the holiday themed comments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

custom_colors_chase_gw = CustomColorsChase(
pixels, speed=0.1, colors=[GREEN, WHITE], size=2, spacing=3
)
# Christmas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, re: removing holiday themed comments.

custom_colors_chase_rg = CustomColorsChase(
pixels, speed=0.1, colors=[RED, GREEN], size=2, spacing=3
)
custom_colors_chase_rg_r = CustomColorsChase(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming this to custom_colors_chase_rg_reversed. It's long, but the difference between the two is clearer.

pixels, speed=0.1, colors=[RED, GREEN], size=1, spacing=2, reverse=True
)
# Valentines Day
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, re: removing holiday themed comments.

custom_colors_chase_rp = CustomColorsChase(
pixels, speed=0.1, colors=[RED, PINK], size=2, spacing=3
)


animations = AnimationSequence(
custom_colors_chase_rainbow,
custom_colors_chase_rp,
custom_colors_chase_gw,
custom_colors_chase_rwb,
custom_colors_chase_rg,
custom_colors_chase_rg_r,
advance_interval=6,
auto_clear=True,
)

while True:
animations.animate()