From 57b28219d687281f3c53e77990f07ca3a7cef916 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 24 May 2018 21:04:48 -0400 Subject: [PATCH 1/2] Updated generate_sample and start_tone to 3.0 Added in checks for backwards compatibility with 2.x. --- adafruit_circuitplayground/express.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/adafruit_circuitplayground/express.py b/adafruit_circuitplayground/express.py index 545257d..46a5bc6 100755 --- a/adafruit_circuitplayground/express.py +++ b/adafruit_circuitplayground/express.py @@ -594,8 +594,14 @@ def _generate_sample(self): if self._sample is not None: return length = 100 - self._sine_wave = array.array("H", Express._sine_sample(length)) - self._sample = audioio.AudioOut(board.SPEAKER, self._sine_wave) + if sys.implementation.version[0] >= 3: + self._sine_wave = array.array("H", Express._sine_sample(length)) + self._sample = audioio.AudioOut(board.SPEAKER) + self._sine_wave_sample = audioio.RawSample(self._sine_wave) + else: + self._sine_wave = array.array("H", Express._sine_sample(length)) + self._sample = audioio.AudioOut(board.SPEAKER, self._sine_wave) + def play_tone(self, frequency, duration): """ Produce a tone using the speaker. Try changing frequency to change @@ -642,9 +648,14 @@ def start_tone(self, frequency): self._speaker_enable.value = True self._generate_sample() # Start playing a tone of the specified frequency (hz). - self._sample.frequency = int(len(self._sine_wave) * frequency) - if not self._sample.playing: - self._sample.play(loop=True) + if sys.implementation.version[0] >= 3: + self._sine_wave_sample.sample_rate = int(len(self._sine_wave) * frequency) + if not self._sample.playing: + self._sample.play(self._sine_wave_sample, loop=True) + else: + self._sample.frequency = int(len(self._sine_wave) * frequency) + if not self._sample.playing: + self._sample.play(loop=True) def stop_tone(self): """ Use with start_tone to stop the tone produced. From 39608f0a7cfd4ff72a34ef9d9c2c6103ca930610 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 24 May 2018 21:09:16 -0400 Subject: [PATCH 2/2] Added attribute to init for linting --- adafruit_circuitplayground/express.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_circuitplayground/express.py b/adafruit_circuitplayground/express.py index 46a5bc6..c5bcdf9 100755 --- a/adafruit_circuitplayground/express.py +++ b/adafruit_circuitplayground/express.py @@ -98,6 +98,7 @@ def __init__(self): self._speaker_enable.switch_to_output(value=False) self._sample = None self._sine_wave = None + self._sine_wave_sample = None # Define touch: # We chose these verbose touch_A# names so that beginners could use it without understanding