Skip to content

Commit f5a4455

Browse files
committed
2 parents d9be6bc + b3fd0ef commit f5a4455

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

adafruit_magtag/peripherals.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,19 @@ def __init__(self):
6565
def play_tone(self, frequency, duration):
6666
"""Automatically Enable/Disable the speaker and play
6767
a tone at the specified frequency for the specified duration
68-
68+
It will attempt to play the sound up to 3 times in the case of
69+
an error.
6970
"""
7071
self._speaker_enable.value = True
71-
simpleio.tone(board.SPEAKER, frequency, duration)
72+
attempt = 0
73+
# Try up to 3 times to play the sound
74+
while attempt < 3:
75+
try:
76+
simpleio.tone(board.SPEAKER, frequency, duration)
77+
break
78+
except NameError:
79+
pass
80+
attempt += 1
7281
self._speaker_enable.value = False
7382

7483
@property

0 commit comments

Comments
 (0)