code.py
 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      'chime',
42      'excellent',
43      'foolish',
44      'hello',
45      'operational',
46      'startours'
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!")