Skip to content

Commit e23e57b

Browse files
committed
reuse formatting. add examples for new functionality
1 parent fe11f17 commit e23e57b

File tree

4 files changed

+59
-36
lines changed

4 files changed

+59
-36
lines changed

adafruit_led_animation/animation/volume.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
# The MIT License (MIT)
1+
# SPDX-FileCopyrightText: 2020 Gamblor21
22
#
3-
# Permission is hereby granted, free of charge, to any person obtaining a copy
4-
# of this software and associated documentation files (the "Software"), to deal
5-
# in the Software without restriction, including without limitation the rights
6-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
# copies of the Software, and to permit persons to whom the Software is
8-
# furnished to do so, subject to the following conditions:
9-
#
10-
# The above copyright notice and this permission notice shall be included in
11-
# all copies or substantial portions of the Software.
12-
#
13-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
# THE SOFTWARE.
3+
# SPDX-License-Identifier: MIT
204
"""
215
`adafruit_led_animation.animation.volume`
226
================================================================================

adafruit_led_animation/timedsequence.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
# The MIT License (MIT)
1+
# SPDX-FileCopyrightText: 2020 Gamblor21
22
#
3-
# Permission is hereby granted, free of charge, to any person obtaining a copy
4-
# of this software and associated documentation files (the "Software"), to deal
5-
# in the Software without restriction, including without limitation the rights
6-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
# copies of the Software, and to permit persons to whom the Software is
8-
# furnished to do so, subject to the following conditions:
9-
#
10-
# The above copyright notice and this permission notice shall be included in
11-
# all copies or substantial portions of the Software.
12-
#
13-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
# THE SOFTWARE.
3+
# SPDX-License-Identifier: MIT
204
"""
215
`adafruit_led_animation.timedsequence`
226
================================================================================
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: 2020 Gamblor21
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Example for TimedSequence
6+
"""
7+
import board
8+
import neopixel
9+
from adafruit_led_animation.timedsequence import TimedAnimationSequence
10+
import adafruit_led_animation.animation.comet as comet_animation
11+
import adafruit_led_animation.animation.sparkle as sparkle_animation
12+
import adafruit_led_animation.animation.blink as blink_animation
13+
from adafruit_led_animation import color
14+
15+
strip_pixels = neopixel.NeoPixel(board.D6, 32, brightness=0.1, auto_write=False)
16+
blink = blink_animation.Blink(strip_pixels, 0.3, color.RED)
17+
comet = comet_animation.Comet(strip_pixels, 0.1, color.BLUE)
18+
sparkle = sparkle_animation.Sparkle(strip_pixels, 0.05, color.GREEN)
19+
animations = TimedAnimationSequence(blink, 2, comet, 4, sparkle, 5)
20+
while True:
21+
animations.animate()

examples/led_animation_volume.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2023 Tim Cocks
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""Volume Animation Example"""
6+
import board
7+
from audiomp3 import MP3Decoder
8+
import neopixel
9+
from adafruit_led_animation.animation import volume
10+
11+
try:
12+
from audioio import AudioOut
13+
except ImportError:
14+
try:
15+
from audiopwmio import PWMAudioOut as AudioOut
16+
except ImportError:
17+
pass # not always supported by every board!
18+
19+
# Fill in your own MP3 file or use the one from the learn guide:
20+
# https://learn.adafruit.com/circuitpython-essentials/circuitpython-mp3-audio#installing-project-code-3067700
21+
mp3file = "happy.mp3"
22+
with open(mp3file, "rb") as mp3:
23+
decoder = MP3Decoder(mp3)
24+
audio = AudioOut(board.SPEAKER)
25+
26+
strip_pixels = neopixel.NeoPixel(board.D4, 30, brightness=0.1, auto_write=False)
27+
volume_anim = volume.Volume(strip_pixels, 0.3, (0, 255, 0), decoder, 400)
28+
29+
while True:
30+
audio.play(decoder)
31+
print("playing", mp3file)
32+
33+
while audio.playing:
34+
volume_anim.animate()

0 commit comments

Comments
 (0)