Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Blink with user color selected background #124

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
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
11 changes: 8 additions & 3 deletions adafruit_led_animation/animation/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ class Blink(ColorCycle):
: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 background_color: Background color in ``(r, g, b)`` tuple, or ``0x000000``
hex format. Defaults to BLACK.
:param name: A human-readable name for the Animation. Used by the string function.
"""

def __init__(self, pixel_object, speed, color, name=None):
super().__init__(pixel_object, speed, [color, BLACK], name=name)
# pylint: disable=too-many-arguments
def __init__(self, pixel_object, speed, color, background_color=BLACK, name=None):
self._background_color = background_color
super().__init__(pixel_object, speed, [color, background_color], name=name)

def _set_color(self, color):
self.colors = [color, BLACK]
self.colors = [color, self._background_color]
17 changes: 15 additions & 2 deletions adafruit_led_animation/animation/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ class Volume(Animation):

# pylint: disable=too-many-arguments
def __init__(
self, pixel_object, speed, brightest_color, decoder, max_volume=500, name=None
self,
pixel_object,
speed,
brightest_color,
decoder,
max_volume=500,
name=None,
):
self._decoder = decoder
self._num_pixels = len(pixel_object)
Expand Down Expand Up @@ -89,8 +95,15 @@ def draw(self):
)

lit_pixels = int(
map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._num_pixels)
map_range(
self._decoder.rms_level,
0,
self._max_volume,
0,
self._num_pixels,
)
)
# pylint: disable=consider-using-min-builtin
if lit_pixels > self._num_pixels:
lit_pixels = self._num_pixels

Expand Down
2 changes: 1 addition & 1 deletion adafruit_led_animation/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AnimationSequence:
animations.animate()
"""

# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-instance-attributes, too-many-arguments
def __init__(
self,
*members,
Expand Down
8 changes: 8 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ Demonstrates the blink animation.
:caption: examples/led_animation_blink.py
:linenos:

Blink with a selcted background color
----------------------------------------
Demonstrates the blink animation with an user defined background color.

.. literalinclude:: ../examples/led_animation_blink_with_background.py
:caption: examples/led_animation_blink_with_background.py
:linenos:

Comet
-----

Expand Down
29 changes: 29 additions & 0 deletions examples/led_animation_blink_with_background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: 2025 Jose D. Montoya
# SPDX-License-Identifier: MIT

"""
This example blinks the LEDs purple with a yellow background at a 0.5 second interval.

For QT Py Haxpress and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if
using a different board or form of NeoPixels.

This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
"""
import board
import neopixel

from adafruit_led_animation.animation.blink import Blink
from adafruit_led_animation.color import PURPLE, YELLOW

# Update to match the pin connected to your NeoPixels
pixel_pin = board.A3
# Update to match the number of NeoPixels you have connected
pixel_num = 30

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

blink = Blink(pixels, speed=0.5, color=PURPLE, background_color=YELLOW)

while True:
blink.animate()