reuse formatting. add examples for new functionality

This commit is contained in:
foamyguy 2023-06-29 19:36:32 -05:00
parent fe11f17986
commit e23e57b421
4 changed files with 59 additions and 36 deletions

View file

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

View file

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

View file

@ -0,0 +1,21 @@
# SPDX-FileCopyrightText: 2020 Gamblor21
#
# SPDX-License-Identifier: MIT
"""
Example for TimedSequence
"""
import board
import neopixel
from adafruit_led_animation.timedsequence import TimedAnimationSequence
import adafruit_led_animation.animation.comet as comet_animation
import adafruit_led_animation.animation.sparkle as sparkle_animation
import adafruit_led_animation.animation.blink as blink_animation
from adafruit_led_animation import color
strip_pixels = neopixel.NeoPixel(board.D6, 32, brightness=0.1, auto_write=False)
blink = blink_animation.Blink(strip_pixels, 0.3, color.RED)
comet = comet_animation.Comet(strip_pixels, 0.1, color.BLUE)
sparkle = sparkle_animation.Sparkle(strip_pixels, 0.05, color.GREEN)
animations = TimedAnimationSequence(blink, 2, comet, 4, sparkle, 5)
while True:
animations.animate()

View file

@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: 2023 Tim Cocks
#
# SPDX-License-Identifier: MIT
"""Volume Animation Example"""
import board
from audiomp3 import MP3Decoder
import neopixel
from adafruit_led_animation.animation import volume
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
# Fill in your own MP3 file or use the one from the learn guide:
# https://learn.adafruit.com/circuitpython-essentials/circuitpython-mp3-audio#installing-project-code-3067700
mp3file = "happy.mp3"
with open(mp3file, "rb") as mp3:
decoder = MP3Decoder(mp3)
audio = AudioOut(board.SPEAKER)
strip_pixels = neopixel.NeoPixel(board.D4, 30, brightness=0.1, auto_write=False)
volume_anim = volume.Volume(strip_pixels, 0.3, (0, 255, 0), decoder, 400)
while True:
audio.play(decoder)
print("playing", mp3file)
while audio.playing:
volume_anim.animate()