Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Thursday, 13 March 2014

Sparkfun Inventor kit in Sniff

I recently stumbled across the Sparkfun Inventor Kit ( - This is a great kit of bits and pieces to get you started with Arduino. It includes a bunch of handy components to get you started, but more importantly it includes a really great guidebook which walks you through 15 mini-projects using the components in the kit.

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
..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 f to 440
.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