From 43ac79a67d50342a3878337de8855d2fb1cd3adc Mon Sep 17 00:00:00 2001 From: Danny Staple Date: Thu, 16 Nov 2023 22:14:49 +0000 Subject: [PATCH] Fix for audio lockup #4 --- examples/modules/audio_amp/wav_play.py | 72 +++++++++++++------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/examples/modules/audio_amp/wav_play.py b/examples/modules/audio_amp/wav_play.py index 295a03c..27a8604 100644 --- a/examples/modules/audio_amp/wav_play.py +++ b/examples/modules/audio_amp/wav_play.py @@ -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()