Skip to content

Commit c7dc901

Browse files
committed
Blink animation with a user selected background color
1 parent 83b87ef commit c7dc901

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

adafruit_led_animation/animation/blink.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ 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`` hex format. Defaults to BLACK.
41+
:param name: A human-readable name for the Animation. Used by the string function.
4042
"""
4143

42-
def __init__(self, pixel_object, speed, color, name=None):
43-
super().__init__(pixel_object, speed, [color, BLACK], name=name)
44+
def __init__(
45+
self, pixel_object, speed, color, background_color=BLACK, name=None
46+
):
47+
self._background_color = background_color
48+
super().__init__(
49+
pixel_object, speed, [color, background_color], name=name
50+
)
4451

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

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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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(
25+
pixel_pin, pixel_num, brightness=0.5, auto_write=False
26+
)
27+
28+
blink = Blink(pixels, speed=0.5, color=PURPLE, background_color=YELLOW)
29+
30+
while True:
31+
blink.animate()

0 commit comments

Comments
 (0)