Skip to content

Commit 74b8dd3

Browse files
committed
Changing from string to number format for waveform selection.
1 parent eb52cea commit 74b8dd3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

adafruit_circuitplayground/circuit_playground_base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
__version__ = "0.0.0-auto.0"
3737
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CircuitPlayground.git"
3838

39-
4039
class Photocell:
4140
"""Simple driver for analog photocell on the Circuit Playground Express and Bluefruit."""
4241

@@ -55,6 +54,8 @@ class CircuitPlaygroundBase: # pylint: disable=too-many-public-methods
5554
"""Circuit Playground base class."""
5655

5756
_audio_out = None
57+
SINE_WAVE = 0
58+
SQUARE_WAVE = 1
5859

5960
def __init__(self):
6061
# Define switch:
@@ -705,23 +706,23 @@ def _square_sample(length):
705706
for _ in range(half_length):
706707
yield 0
707708

708-
def _generate_sample(self, length=100, waveform="sine"):
709+
def _generate_sample(self, length=100, waveform=SINE_WAVE):
709710
if self._sample is not None:
710711
return
711-
if waveform == "square":
712+
if waveform == self.SQUARE_WAVE:
712713
self._wave = array.array("H", self._square_sample(length))
713714
else:
714715
self._wave = array.array("H", self._sine_sample(length))
715716
self._sample = self._audio_out(board.SPEAKER) # pylint: disable=not-callable
716717
self._wave_sample = audiocore.RawSample(self._wave)
717718

718-
def play_tone(self, frequency, duration, waveform="sine"):
719+
def play_tone(self, frequency, duration, waveform=SINE_WAVE):
719720
"""Produce a tone using the speaker. Try changing frequency to change
720721
the pitch of the tone.
721722
722723
:param int frequency: The frequency of the tone in Hz
723724
:param float duration: The duration of the tone in seconds
724-
:param str waveform: Type of waveform to be generated [sine, square]. Default = sine.
725+
:param str waveform: Type of waveform to be generated [SINE_WAVE, SQUARE_WAVE]. Default = SINE_WAVE.
725726
726727
.. image :: ../docs/_static/speaker.jpg
727728
:alt: Onboard speaker
@@ -739,12 +740,12 @@ def play_tone(self, frequency, duration, waveform="sine"):
739740
time.sleep(duration)
740741
self.stop_tone()
741742

742-
def start_tone(self, frequency, waveform="sine"):
743+
def start_tone(self, frequency, waveform=SINE_WAVE):
743744
"""Produce a tone using the speaker. Try changing frequency to change
744745
the pitch of the tone.
745746
746747
:param int frequency: The frequency of the tone in Hz
747-
:param str waveform: Type of waveform to be generated [sine, square]. Default = sine.
748+
:param str waveform: Type of waveform to be generated [SINE_WAVE, SQUARE_WAVE]. Default = SINE_WAVE.
748749
749750
.. image :: ../docs/_static/speaker.jpg
750751
:alt: Onboard speaker

0 commit comments

Comments
 (0)