Skip to content

Added speaker tones to Circuit Playground Express CircuitPython API. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 19, 2017

Conversation

kattni
Copy link
Contributor

@kattni kattni commented Sep 16, 2017

Included image for docs.

@tannewt tannewt self-requested a review September 18, 2017 03:03
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks close! Thanks for the pull request!

@@ -63,6 +66,10 @@ def __init__(self):
self._temp = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
self._light = Photocell(board.LIGHT)

# Define audio:
self.speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
self.speaker_enable.switch_to_output(value=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not set the value to True until we want to play sound. Otherwise the speaker will crackle randomly.

def play_tone(self, frequency, duration):
""" Produce a tone using the speaker.

.. image :: /_static/speaker.jpg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty lines are weirdly important so you'll need one after the image line and after the paragraph below.

sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)

sample = audioio.AudioOut(board.SPEAKER, sine_wave)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the speaker enable toggle here and after stop.

@@ -184,6 +191,30 @@ def red_led(self):
def red_led(self, value):
self._led.value = value

def play_tone(self, frequency, duration):
""" Produce a tone using the speaker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document the two arguments frequency and duration using the param style here: https://github.com/adafruit/Adafruit_CircuitPython_DotStar/blob/master/adafruit_dotstar.py#L39

kattni and others added 2 commits September 18, 2017 18:43
Python only associates comments with the method itself when they are the first thing in the method. Also add param types.
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @kattni! I made two minor changes and will pull it now.

@tannewt tannewt merged commit 9e47823 into adafruit:master Sep 19, 2017
@kattni kattni deleted the speaker-implementation branch September 20, 2017 20:29
@kattni kattni restored the speaker-implementation branch September 20, 2017 20:29
@kattni kattni deleted the speaker-implementation branch September 20, 2017 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants