Hackers in Residence - The ElectricBone

Pages
Contributors: Carlos E. Mello
Favorited Favorite 4

Firmware

The ElectricBone sketch, found here, defines three output modes, which can be toggled by the small button installed on the control box. Of these three modes, only the first one, MIDI Mode, is currently implemented. After a few lines of debouncing code for the mode button, the sketch switches on the selected mode to decide how to produce sounds.

In order to make the Arduino code more manageable, I split it into a few independent blocks which went inside separate functions. This way it is possible to visualize the entire algorithm at once just by glancing at the main loop.

The first of these functions, gateStatus(), returns the current status of the gate pin. If the pin just turned HIGH after being LOW, gateStatus() returns GATE_START. If the pin just turned LOW after being HIGH, the function returns GATE_END. While between a START and an END, gateSatus() will return GATE_ON. When there is no gate activity, the function returns GATE_OFF. Switching on the output of this function consitutes the basic skeleton for the ElectricBone algorithm.

From there, all we have to do is call the other functions to retrieve the current state of the sensors: trackSlide() returns the slide position in cm; slidePosition() calculates the position number for the value received from trackSlide(); harmonic() gets a harmonic number from the current Softpot input; pitchNumber() picks a MIDI note number based on the slide position and harmonic number. Once we have that information we send a message to the MIDI port using sendMIDI(). When gateStatus reports a GATE_END, the code sends Note Off to MIDI.

Interested in learning more about distance sensing?

Learn all about the different technologies distance sensors use and which products would work best for you next project.

Take me there!