Skip to content

Commit 5c8d64d

Browse files
authored
Merge pull request #94 from tekktrik/doc/add-pause-example
Add push button examples for pausing, resuming, and cycling animations
2 parents c203abd + a50aea4 commit 5c8d64d

3 files changed

+122
-0
lines changed
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SPDX-FileCopyrightText: 2021 Alec Delaney
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This example uses AnimationsSequence along with a connected push button to cycle through
6+
two animations
7+
8+
For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
9+
a different form of NeoPixels.
10+
"""
11+
import time
12+
import board
13+
import neopixel
14+
from digitalio import DigitalInOut, Direction, Pull
15+
16+
from adafruit_led_animation.animation.solid import Solid
17+
from adafruit_led_animation.sequence import AnimationSequence
18+
from adafruit_led_animation.color import RED, BLUE
19+
20+
# Update to match the pin connected to your NeoPixels
21+
pixel_pin = board.D6
22+
# Update to match the number of NeoPixels you have connected
23+
pixel_num = 32
24+
25+
# Update to matchpin connected to button that connect logic high when pushed
26+
button_pin = board.D3
27+
28+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
29+
button = DigitalInOut(button_pin)
30+
button.direction = Direction.INPUT
31+
button.pull = Pull.UP
32+
33+
solid_blue = Solid(pixels, color=BLUE)
34+
solid_red = Solid(pixels, color=RED)
35+
animation_sequence = AnimationSequence(solid_blue, solid_red, auto_clear=True)
36+
37+
while True:
38+
animation_sequence.animate()
39+
40+
# Pressing the button pauses the animation permanently
41+
if not button.value:
42+
animation_sequence.next()
43+
while button.value:
44+
time.sleep(0.1) # Used for button debouncing
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: 2021 Alec Delaney
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This example uses Pulse animation along with a connected push button to freeze
6+
the animation permanently when pressed
7+
8+
For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
9+
a different form of NeoPixels.
10+
"""
11+
import board
12+
import neopixel
13+
from digitalio import DigitalInOut, Direction, Pull
14+
15+
from adafruit_led_animation.animation.pulse import Pulse
16+
from adafruit_led_animation.color import RED
17+
18+
# Update to match the pin connected to your NeoPixels
19+
pixel_pin = board.D6
20+
# Update to match the number of NeoPixels you have connected
21+
pixel_num = 32
22+
23+
# Update to matchpin connected to button that connect logic high when pushed
24+
button_pin = board.D3
25+
26+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
27+
button = DigitalInOut(button_pin)
28+
button.direction = Direction.INPUT
29+
button.pull = Pull.UP
30+
31+
pulse_animation = Pulse(pixels, speed=0.1, period=1, color=RED)
32+
33+
while True:
34+
pulse_animation.animate()
35+
36+
# Pressing the button pauses the animation permanently
37+
if not button.value:
38+
pulse_animation.freeze()
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-FileCopyrightText: 2021 Alec Delaney
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This example uses Pulse animation along with a connected push button to start
6+
the animation when pressed
7+
8+
For NeoPixel FeatherWing. Update pixel_pin and pixel_num to match your wiring if using
9+
a different form of NeoPixels.
10+
"""
11+
import board
12+
import neopixel
13+
from digitalio import DigitalInOut, Direction, Pull
14+
15+
from adafruit_led_animation.animation.pulse import Pulse
16+
from adafruit_led_animation.color import RED
17+
18+
# Update to match the pin connected to your NeoPixels
19+
pixel_pin = board.D6
20+
# Update to match the number of NeoPixels you have connected
21+
pixel_num = 32
22+
23+
# Update to matchpin connected to button that connect logic high when pushed
24+
button_pin = board.D3
25+
26+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=0.5, auto_write=False)
27+
button = DigitalInOut(button_pin)
28+
button.direction = Direction.INPUT
29+
button.pull = Pull.UP
30+
31+
# Create the animation and freeze it afterwards
32+
pulse_animation = Pulse(pixels, speed=0.1, period=1, color=RED)
33+
pulse_animation.freeze()
34+
35+
while True:
36+
pulse_animation.animate()
37+
38+
# Pressing the button resumes (or in this case starts) the animation permanently
39+
if not button.value:
40+
pulse_animation.resume()

0 commit comments

Comments
 (0)