Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…thon_MagTag into main
  • Loading branch information
makermelissa committed Nov 20, 2020
2 parents d9be6bc + b3fd0ef commit f5a4455
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions adafruit_magtag/peripherals.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ def __init__(self):
def play_tone(self, frequency, duration):
"""Automatically Enable/Disable the speaker and play
a tone at the specified frequency for the specified duration
It will attempt to play the sound up to 3 times in the case of
an error.
"""
self._speaker_enable.value = True
simpleio.tone(board.SPEAKER, frequency, duration)
attempt = 0
# Try up to 3 times to play the sound
while attempt < 3:
try:
simpleio.tone(board.SPEAKER, frequency, duration)
break
except NameError:
pass
attempt += 1
self._speaker_enable.value = False

@property
Expand Down

0 comments on commit f5a4455

Please sign in to comment.