play files
This commit is contained in:
parent
227083fe0e
commit
415e3c00d0
3 changed files with 35 additions and 0 deletions
|
|
@ -0,0 +1,35 @@
|
|||
from digitalio import DigitalInOut, Direction, Pull
|
||||
import audioio
|
||||
import board
|
||||
|
||||
# enable the speaker
|
||||
spkrenable = DigitalInOut(board.SPEAKER_ENABLE)
|
||||
spkrenable.direction = Direction.OUTPUT
|
||||
spkrenable.value = True
|
||||
|
||||
# make the 2 input buttons
|
||||
buttonA = DigitalInOut(board.BUTTON_A)
|
||||
buttonA.direction = Direction.INPUT
|
||||
buttonA.pull = Pull.DOWN
|
||||
|
||||
buttonB = DigitalInOut(board.BUTTON_B)
|
||||
buttonB.direction = Direction.INPUT
|
||||
buttonB.pull = Pull.DOWN
|
||||
|
||||
# The two files assigned to buttons A & B
|
||||
audiofiles = ["rimshot.wav", "laugh2.wav"]
|
||||
|
||||
def play_file(filename):
|
||||
print("playing file "+filename)
|
||||
f = open(filename, "rb")
|
||||
a = audioio.AudioOut(board.A0, f)
|
||||
a.play()
|
||||
while a.playing:
|
||||
pass
|
||||
print("finished")
|
||||
|
||||
while True:
|
||||
if buttonA.value:
|
||||
play_file(audiofiles[0])
|
||||
if buttonB.value:
|
||||
play_file(audiofiles[1])
|
||||
BIN
Introducing_CircuitPlaygroundExpress/laugh.wav
Normal file
BIN
Introducing_CircuitPlaygroundExpress/laugh.wav
Normal file
Binary file not shown.
BIN
Introducing_CircuitPlaygroundExpress/rimshot.wav
Normal file
BIN
Introducing_CircuitPlaygroundExpress/rimshot.wav
Normal file
Binary file not shown.
Loading…
Reference in a new issue