Today I'm proud to present a guest post from Sam, my 12 year old. Sam recently took part in a maker-focused summer camp held here in Chapel Hill.

Introduction

I recently took a class from Ninjaneering Labs that used an Arduino compatible Redboard from SparkFun to build a musical instrument. We used a couple different shields to make a digital trumpet.

Architecture

My digital trumpet is created by stacking a shield on a musical shield from Sparkfun, which was stacked on top of a Redboard. A speaker was plugged into the music shield, then hot glued on to the front of a small breadboard.

We used the Arduino programming language which is an implementation of Wiring.

Code

Here is the Wiring code I used to power my instrument:

#include <SoftwareSerial.h>
#include <SFMusicalShield.h>

SoftwareSerial mySerial(2,3);
SFMusicalShield music;

void setup() {
  mySerial.begin(31250);

  music.begin(mySerial);

  music.setBank(0, BASIC_INSTRUMENTS);
  music.setInstrument(0, 57);

  music.setVolume(0,127);

}

long lastDetect[]={
  -1,-1,-1};
int pushButton[]={
  7,6,2};
int notes[]= {
  63,68,75};

void loop() {
  long currentTime = millis();
  for ( int i=0;i<3;i++){
    boolean state =! digitalRead(pushButton[i]);
    if(state == true) {
      if (currentTime-lastDetect[i]>20){
        music.noteOn(0,notes[i],127);
      }
      lastDetect[i] = currentTime;
    }
    else{
      music.noteOff(0, notes[i] ,127);
    }
  }
}

To hook up the redboard to the musical shield, I use lines 8 and 10 to tell the redboard which serial port the musical shield is on.

On lines 12 and 13 of the code, I am telling the Arduino and musical shield to select the basic set of instruments, and select number 57 from that bank of instruments.

Line 29 selects which button I am pressing and selects the correct instrument tone.

Wrap Up

The next thing I would like to do is add a knob to select different instruments from different instruments.

My dad is going to pay me to make a garage door open sensor that transmits status to a remote raspberry pi or arduino and what I learned from this class will be very helpful.