It's a great way for kids to get started, but of course it used standard Arduino/C++ which is probably going to be hard work for younger kids (the kit is listed as being for ages 10+, which is probably reasonable in terms of the physical components but ambitious in terms of the coding), so I thought it would be fun to rewrite the 15 examples in Sniff.
Most of the examples are pretty simple to convert, but some are more interesting. Example 11 uses the Tone function of the Arduino library, but Sniff has no sound support. However it turns out you can write your own sound code in Sniff pretty easily:
when makeSounds
.forever
..set buzzer to on
..wait halfWavelength microsecs
..set buzzer to off
..wait halfWavelength microsecs
What's great about this is you can actually see that to play a sound we're pushing the speaker cone forwards and backwards. To play A440 for half a second you just have to write:
.set halfWavelength to 500000/f
.wait 0.5 secs
.set halfWavelength to 0
Setting the half wavelength to 0 makes the sound well outside of human hearing (and the capabilities of any audio system to reproduce it!) The full example uses a string of note names, from which we pick out the letters, and look them up in a list to find their frequency.
You can download the full set of SIK examples from the link below. They're not all fully tested, as I don't have the exact components needed, so there's sure to be a few bugs - let us know so we can fix them. This code will be included with the examples in future Sniff releases.
No comments:
Post a Comment