Skip to content

Commit

Permalink
Fix for audio lockup pimoroni#4
Browse files Browse the repository at this point in the history
  • Loading branch information
dannystaple committed Nov 16, 2023
1 parent 3410a50 commit 43ac79a
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions examples/modules/audio_amp/wav_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,44 @@ def button_newly_pressed(btn):
print(f"- Press 'A' to play '{WAV_FILE_A}', or stop what is currently playing")
print(f"- Press 'B' to play '{WAV_FILE_B}', or stop what is currently playing")
print() # New line

# Loop until the BOOT/USER button is pressed
while not yukon.is_boot_pressed():

# Has the button been pressed?
if button_newly_pressed('A'):
# Is nothing playing?
if not amp.player.is_playing():
amp.player.play_wav(WAV_FILE_A) # Play file A
amp.set_volume(VOLUME_A) # Set the volume to play file A at
yukon.set_led('A', True) # Show that file A is playing
print("Playing the first WAV file")
else:
amp.player.stop() # Stop whichever file is currently playing
print("Stopping playback")

# Has the button been pressed?
if button_newly_pressed('B'):
# Is nothing playing?
try:
# Loop until the BOOT/USER button is pressed
while not yukon.is_boot_pressed():

# Has the button been pressed?
if button_newly_pressed('A'):
# Is nothing playing?
if not amp.player.is_playing():
amp.player.play_wav(WAV_FILE_A) # Play file A
amp.set_volume(VOLUME_A) # Set the volume to play file A at
yukon.set_led('A', True) # Show that file A is playing
print("Playing the first WAV file")
else:
amp.player.stop() # Stop whichever file is currently playing
print("Stopping playback")

# Has the button been pressed?
if button_newly_pressed('B'):
# Is nothing playing?
if not amp.player.is_playing():
amp.player.play_wav(WAV_FILE_B) # Play file B
amp.set_volume(VOLUME_B) # Set the volume to play file B at
yukon.set_led('B', True) # Show that file B is playing
print("Playing the second WAV file")
else:
amp.player.stop() # Stop whichever file is currently playing
print("Stopping playback")

# Has either file stopped playing?
if not amp.player.is_playing():
amp.player.play_wav(WAV_FILE_B) # Play file B
amp.set_volume(VOLUME_B) # Set the volume to play file B at
yukon.set_led('B', True) # Show that file B is playing
print("Playing the second WAV file")
else:
amp.player.stop() # Stop whichever file is currently playing
print("Stopping playback")

# Has either file stopped playing?
if not amp.player.is_playing():
yukon.set_led('A', False)
yukon.set_led('B', False)

# Perform a single check of Yukon's internal voltage, current, and temperature sensors
yukon.monitor_once()

yukon.set_led('A', False)
yukon.set_led('B', False)

# Perform a single check of Yukon's internal voltage, current, and temperature sensors
yukon.monitor_once()
finally:
amp.player.stop()

finally:
# Put the board back into a safe state, regardless of how the program may have ended
yukon.reset()

0 comments on commit 43ac79a

Please sign in to comment.