Skip to content

Fix Piezo.prototype.note() #1328

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
Apr 21, 2017

Conversation

islemaster
Copy link
Contributor

Re-opening #1324, which automatically closed when I merged code-dot-org#3; see that PR for discussion. Sorry about that! FYI @rwaldron @lyzadanger

The note() method was passing a frequency (Hz) to the tone() method, which is expecting to receive a duty cycle (μs), leading to the wrong note being played. The solution is for note() to call frequency() instead, which will do the appropriate conversion.

Since it took me a while to understand the relationships between tone, frequency and note I've added some documentation to those methods to clear things up for the next person. I've also made some unit tests more aggressive about checking that values are converted appropriately as they're passed around, and commented note-frequency-duty equivalencies to help the test read nicer.

The `note()` method was passing a frequency (Hz) to the `tone()` method, which is expecting to receive a duty cycle (μs), leading to the wrong note being played.  The solution is for `note()` to call `frequency()` instead, which will do the appropriate conversion.

Since it took me a while to understand the relationships between `tone`, `frequency` and `note` I've added some documentation to those methods to clear things up for the next person.  I've also made some unit tests more aggressive about checking that values are converted appropriately as they're passed around, and commented note-frequency-duty equivalencies to help the test read nicer.
- Test that `note()` is case-insensitive
- Better description of default octave
- One-line Piezo.prototype.note
- s/frequncy/frequency
- Note tests demonstrate the difference between note letter and octave number better
@islemaster
Copy link
Contributor Author

islemaster commented Apr 21, 2017

Note: I'm not sure what's up with the failure in this test run and I'm unable to re-run tests on your repo, but I'm pretty sure it's flaky. Here's a passing Travis run at 050489e. I've proposed some changes to help with test flakiness over here.

@rwaldron
Copy link
Owner

@lyzadanger is this good to go? @islemaster addressed the test breakage in a different patch

@lyzadanger
Copy link
Collaborator

LGTM 👍

@rwaldron rwaldron merged commit 001f27f into rwaldron:master Apr 21, 2017
@rwaldron
Copy link
Owner

I will do a release asap.

@islemaster islemaster deleted the piezo-note-calls-frequency branch April 21, 2017 17:08
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.

3 participants