Adding code for magic band reader
Adding code for magic band reader
This commit is contained in:
parent
45067fff0c
commit
a03599ec47
1 changed files with 68 additions and 0 deletions
68
Magic_Band_Reader/code.py
Executable file
68
Magic_Band_Reader/code.py
Executable file
|
|
@ -0,0 +1,68 @@
|
|||
# SPDX-FileCopyrightText: 2022 Noe Ruiz for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
# Magic Band Reader with Wiz Kit RFID
|
||||
import time
|
||||
import random
|
||||
import board
|
||||
import digitalio
|
||||
import audiobusio
|
||||
from audiocore import WaveFile
|
||||
|
||||
try:
|
||||
from audioio import AudioOut
|
||||
except ImportError:
|
||||
try:
|
||||
from audiopwmio import PWMAudioOut as AudioOut
|
||||
except ImportError:
|
||||
pass # not always supported by every board!
|
||||
|
||||
import neopixel
|
||||
from adafruit_led_animation.animation.chase import Chase
|
||||
from adafruit_led_animation.animation.solid import Solid
|
||||
from adafruit_led_animation.color import (
|
||||
GREEN,
|
||||
PINK,
|
||||
BLACK,
|
||||
)
|
||||
|
||||
# Setup button switch
|
||||
button = digitalio.DigitalInOut(board.A1)
|
||||
button.switch_to_input(pull=digitalio.Pull.DOWN)
|
||||
|
||||
# LRC is word_select, BCLK is bit_clock, DIN is data_pin.
|
||||
# Feather RP2040
|
||||
audio = audiobusio.I2SOut(bit_clock=board.D24, word_select=board.D25, data=board.A3)
|
||||
|
||||
# Make the neopixel object
|
||||
pixels = neopixel.NeoPixel(board.D6, 24, brightness=.4)
|
||||
|
||||
# Setup the LED animations
|
||||
chase = Chase(pixels, speed=0.02, color=GREEN, size=4, spacing=24)
|
||||
solid = Solid(pixels, color=BLACK)
|
||||
|
||||
#Fuction for playing audio
|
||||
def play_wav(name):
|
||||
print("playing", name)
|
||||
wave_file = open('sounds/' + name + '.wav', 'rb')
|
||||
wave = WaveFile(wave_file)
|
||||
audio.play(wave)
|
||||
|
||||
#List of audio files
|
||||
sounds = [
|
||||
'electrons',
|
||||
'hello',
|
||||
'meetyou',
|
||||
'excellent22',
|
||||
'whhaatt',
|
||||
'uhoh-adabot'
|
||||
]
|
||||
while True:
|
||||
print("Waiting for button press to continue!")
|
||||
while button.value:
|
||||
pass
|
||||
solid.animate()
|
||||
play_wav(random.choice(sounds))
|
||||
while audio.playing:
|
||||
pass
|
||||
chase.animate()
|
||||
print("Done!")
|
||||
Loading…
Reference in a new issue