Snippet - Gadgeteer Sounds using eBlock Piezos

[title]Gadgeteer Sounds using eBlock Piezos[/title]
This is a sample that demonstrates the use of 3-pin eblocks to add functionality to .NET Gadgeteer that may not be currently available via a Gadgeteer module. In this specific demo, I am using 2 eblock piezos, connected via the eblock Expansion Module (

The complete project is available as an attachment to this post, or you can simply use the code below as a guide for driving the piezos. The image associated with this code submission shows how the modules are hooked up.

One thing to note…since I’m using 2 eblock Expansion Modules, and 2 piezos, you should double-check that the piezos are connected both to the correct Expansion Module AND to the correct pin on the Expansion Module. If you don’t hear sound, make sure these are connected properly (or just use one Expansion Module/Piezo, and comment out the code for the other one).

The project uses a button module to start and stop a timer, which polls the value of 2 potentiometer modules, and uses that value to modulate the frequency being set on the piezo. You can experiment with the first parameter of the line Piezo1.Set(440 * Pot1Pct, 50); to see how different frequencies or different modulations from the potentiometer affect the sound.

There is also a section of the code, commented out by default, which walks the piezos up and down a simple scale. If you uncomment this code, I also recommend that you comment out the code that enables the timer, since the two sounds don’t work all that well together.

There will likely be an actual Gadgeteer piezo module before too long, given that our friend Architect (aka Valentin Ivanov) has already designed a simple one:

and GHI is running a contest for the best Gadgeteer piezo design:

but there are still many useful eblocks that you can use in your Gadgeteer projects.