Skip to content

Commit 37800fe

Browse files
authored
Merge pull request #124 from jposada202020/blink-with-user-color-selected-background
Blink with user color selected background
2 parents 83b87ef + 34bcf3c commit 37800fe

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

adafruit_led_animation/animation/blink.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ class Blink(ColorCycle):
3737
:param pixel_object: The initialised LED object.
3838
:param float speed: Animation speed in seconds, e.g. ``0.1``.
3939
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
40+
:param background_color: Background color in ``(r, g, b)`` tuple, or ``0x000000``
41+
hex format. Defaults to BLACK.
42+
:param name: A human-readable name for the Animation. Used by the string function.
4043
"""
4144

42-
def __init__(self, pixel_object, speed, color, name=None):
43-
super().__init__(pixel_object, speed, [color, BLACK], name=name)
45+
# pylint: disable=too-many-arguments
46+
def __init__(self, pixel_object, speed, color, background_color=BLACK, name=None):
47+
self._background_color = background_color
48+
super().__init__(pixel_object, speed, [color, background_color], name=name)
4449

4550
def _set_color(self, color):
46-
self.colors = [color, BLACK]
51+
self.colors = [color, self._background_color]

adafruit_led_animation/animation/volume.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ class Volume(Animation):
4444

4545
# pylint: disable=too-many-arguments
4646
def __init__(
47-
self, pixel_object, speed, brightest_color, decoder, max_volume=500, name=None
47+
self,
48+
pixel_object,
49+
speed,
50+
brightest_color,
51+
decoder,
52+
max_volume=500,
53+
name=None,
4854
):
4955
self._decoder = decoder
5056
self._num_pixels = len(pixel_object)
@@ -89,8 +95,15 @@ def draw(self):
8995
)
9096

9197
lit_pixels = int(
92-
map_range(self._decoder.rms_level, 0, self._max_volume, 0, self._num_pixels)
98+
map_range(
99+
self._decoder.rms_level,
100+
0,
101+
self._max_volume,
102+
0,
103+
self._num_pixels,
104+
)
93105
)
106+
# pylint: disable=consider-using-min-builtin
94107
if lit_pixels > self._num_pixels:
95108
lit_pixels = self._num_pixels
96109

adafruit_led_animation/sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class AnimationSequence:
7373
animations.animate()
7474
"""
7575

76-
# pylint: disable=too-many-instance-attributes
76+
# pylint: disable=too-many-instance-attributes, too-many-arguments
7777
def __init__(
7878
self,
7979
*members,

docs/examples.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ Demonstrates the blink animation.
6161
:caption: examples/led_animation_blink.py
6262
:linenos:
6363

64+
Blink with a selcted background color
65+
----------------------------------------
66+
Demonstrates the blink animation with an user defined background color.
67+
68+
.. literalinclude:: ../examples/led_animation_blink_with_background.py
69+
:caption: examples/led_animation_blink_with_background.py
70+
:linenos:
71+
6472
Comet
6573
-----
6674

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: 2025 Jose D. Montoya
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This example blinks the LEDs purple with a yellow background at a 0.5 second interval.
6+
7+
For QT Py Haxpress and a NeoPixel strip. Update pixel_pin and pixel_num to match your wiring if
8+
using a different board or form of NeoPixels.
9+
10+
This example will run on SAMD21 (M0) Express boards (such as Circuit Playground Express or QT Py
11+
Haxpress), but not on SAMD21 non-Express boards (such as QT Py or Trinket).
12+
"""
13+
import board
14+
import neopixel
15+
16+
from adafruit_led_animation.animation.blink import Blink
17+
from adafruit_led_animation.color import PURPLE, YELLOW
18+
19+
# Update to match the pin connected to your NeoPixels
20+
pixel_pin = board.A3
21+
# Update to match the number of NeoPixels you have connected
22+
pixel_num = 30
23+
24+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
25+
26+
blink = Blink(pixels, speed=0.5, color=PURPLE, background_color=YELLOW)
27+
28+
while True:
29+
blink.animate()

0 commit comments

Comments
 (0)