Skip to content

Commit 0e1dd5d

Browse files
authored
Merge pull request #2312 from adafruit/magic_band_reader
Adding code for magic band reader
2 parents 45067ff + 33eec67 commit 0e1dd5d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Magic_Band_Reader/code.py

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

0 commit comments

Comments
 (0)