Musical Shield Project - Ian and Nick
Ian and Nick - Musical Shield Project
We used a sound board in order to play different sounds through a speaker, which we then hooked up to a dial to change the different sounds and used a light sensor in order to change the pitch or frequency of the sound.
We used switch case and analog read for a majority of our code.
Pictures of your device
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
byte note = 0;
byte resetMIDI = 4;
byte ledPin = 13;
int instrument = 0;
int notes=0;
int var;
void setup() {
Serial.begin(57600);
mySerial.begin(31250);
pinMode(resetMIDI, OUTPUT);
digitalWrite(resetMIDI, LOW);
delay(100);
digitalWrite(resetMIDI, HIGH);
delay(100);
talkMIDI(0xB0, 0x07, 120);
}
void loop() {
//=================================================================
Serial.println("Basic Instruments");
talkMIDI(0xB0, 0, 0x79);
notes=analogRead(A2);
notes=map(notes,0,1023,30,90);
var=analogRead(A3);
var=map(var,0,1023,1,5);
noteOn(0, notes,90);
delay(100) ;
noteOff(0, notes, 90);
delay(100);
switch (var)
{
case 1:
talkMIDI(0xC0, 74, 0);
break;
case 2:
talkMIDI(0xC0, 106, 0);
break;
case 3:
talkMIDI(0xC0, 120, 0);
break;
case 4:
talkMIDI(0xC0, 30, 0);
break;
case 5:
talkMIDI(0xC0, 3, 0);
break;
default:
break;
}
}
void noteOn(byte channel, byte note, byte attack_velocity) {
talkMIDI( (0x90 | channel), note, attack_velocity);
}
void noteOff(byte channel, byte note, byte release_velocity) {
talkMIDI( (0x80 | channel), note, release_velocity);
}
void talkMIDI(byte cmd, byte data1, byte data2) {
digitalWrite(ledPin, HIGH);
mySerial.write(cmd);
mySerial.write(data1);
if( (cmd & 0xF0) <= 0xB0)
mySerial.write(data2);
digitalWrite(ledPin, LOW);
}
Throughout the entire project we encountered a series of problems ranging from hardwire issues to coding issues. Most of the time the code would not cooperate and would not upload. So we would have to look through the entire code to figure out what was causing problems. Also, we had problems with wires not working, resistors being too big or too small or things just not working all together. At times we would just hit a road block and were unable to continue without help.
If we had more money, we would have added bigger speakers. Other than that there is nothing we would have added.