Skip to content

Commit a03599e

Browse files
committed
Adding code for magic band reader
Adding code for magic band reader
1 parent 45067ff commit a03599e

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Magic_Band_Reader/code.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SPDX-FileCopyrightText: 2022 Noe Ruiz for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
# Magic Band Reader with Wiz Kit RFID
4+
import time
5+
import random
6+
import board
7+
import digitalio
8+
import audiobusio
9+
from audiocore import WaveFile
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+
import neopixel
20+
from adafruit_led_animation.animation.chase import Chase
21+
from adafruit_led_animation.animation.solid import Solid
22+
from adafruit_led_animation.color import (
23+
GREEN,
24+
PINK,
25+
BLACK,
26+
)
27+
28+
# Setup button switch
29+
button = digitalio.DigitalInOut(board.A1)
30+
button.switch_to_input(pull=digitalio.Pull.DOWN)
31+
32+
# LRC is word_select, BCLK is bit_clock, DIN is data_pin.
33+
# Feather RP2040
34+
audio = audiobusio.I2SOut(bit_clock=board.D24, word_select=board.D25, data=board.A3)
35+
36+
# Make the neopixel object
37+
pixels = neopixel.NeoPixel(board.D6, 24, brightness=.4)
38+
39+
# Setup the LED animations
40+
chase = Chase(pixels, speed=0.02, color=GREEN, size=4, spacing=24)
41+
solid = Solid(pixels, color=BLACK)
42+
43+
#Fuction for playing audio
44+
def play_wav(name):
45+
print("playing", name)
46+
wave_file = open('sounds/' + name + '.wav', 'rb')
47+
wave = WaveFile(wave_file)
48+
audio.play(wave)
49+
50+
#List of audio files
51+
sounds = [
52+
'electrons',
53+
'hello',
54+
'meetyou',
55+
'excellent22',
56+
'whhaatt',
57+
'uhoh-adabot'
58+
]
59+
while True:
60+
print("Waiting for button press to continue!")
61+
while button.value:
62+
pass
63+
solid.animate()
64+
play_wav(random.choice(sounds))
65+
while audio.playing:
66+
pass
67+
chase.animate()
68+
print("Done!")

0 commit comments

Comments
 (0)