Below is the sketch where I am trying to incorporate the MIDI decoder using the sparkfun MIDI shield. This is where i need more help and better understanding
//set gate time for each device in milliseconds
int crash=15;
int snare=20;
int smalltom=20; //Durations for each motor to be activated/turned on
int largetom=20;
int cowbell=20;
int gatetime [5] = {crash,snare,smalltom,largetom,cowbell}; //Array that stores gate times for each instrument
unsigned long timenow [5];//Array that stores the current duration for each note, see below for more
byte incomingByte;
byte note;
byte velocity
int action = 13; //select the pin for the LED
int action=2; //0=note off; 1=note on; 2= nada
//-----------------------------------------------------------------------------------------------
void setup() //Assigns appropriate roles to pins
{
for (int i=8;i<15;i++)//pins 8-14
pinMode(i, OUTPUT);//pins 8-14 are outputs
for (int i=2;i<8;i++)//2-7 inputs from MIDI decoder board
pinMode (i, INPUT); //pin 2-7 are inputs
pinMode(statusLed,OUTPUT)//declare the LED's pin as output
MIDI.begin(MIDI_CHANNEL_OMNI);// chooses all MIDI chanels
Serial.begin(31250)
digitalWrite(statusLED,HIGH);
}
//-----------------------------------------------------------------------------------------------
void loop()//Pin 7 determines what type of action if it is high- synth, low = actual instrument
{
if (Serial.available() > 0){
incomingByte = Serial.read();//read incoming byte
if (incomingByte== 144)//note on message starting
action=1;
}else if (incomingByte== 128){ //note off message starting
action=0;
}else if ( (action==0)&&(note==0) ){ //if we receive a "note off", we wait for the note (databyte)
note=incomingByte:
playNote(note, velocity)
note=0
}else if ( (action==1)&&(note==0) ){//if we recieved a "note on" , we wait for the note (databyte)
note=incomingByte:
}else if 9 )action==1)&&(note!=0) ){//and then the velocity
velocity=incomingByte
playNote(note, velocity);
note=0
velocity=0
action=0
}else{ //nada
}
void playNote(byte note, byte velocity){
int value=LOW;
if (velocity >10){
value=HIGH;
}else{
value=LOW;
}
if (note>=36 && note<44){//since we don't want to play all notes we wait for a note between
//36 and 44
byte myPin=note-34); //to get a pinnumber between 2 and 9
digitalWrite (myPin, value);
if (digitalRead(7)==LOW)//inputs low = analog (synth music)
{
digitalWrite(14, HIGH);//pin 14 is on (enables power to the speaker relay, turns speaker on)
for (int i=0; i<5; i++)//pins 8 to 12 low loop
{
digitalWrite(i+8,LOW);//digital outputs low (turns of actual instruments)
}
}
else //this means pin 7 is HIGH - actual instruments to be played
{
digitalWrite (14, LOW);//analog speaker relay power off, no synth music
for (int i=0;i<5;i++)//loops through all the input pins for actual instruments
{
if (digitalRead(i+2)==HIGH)//tests if the current pin is HIGH, if so... go below
{
timenow*=millis();//The slot in timenow gets the current program lifetime*
- digitalWrite(i+8, HIGH);//write HIGH to the corresponding output pin for actual drum that matches the input pin*
- }*
if (millis() > timenow_+gatetime*)//if the current program lifetime is greater than how long the instrument should be playing plus when it started playing, then go on...
{
digitalWrite (i+8,LOW);//turn the instrument off...this means the motor has been playing for long enough (gatetime for the drum)
}
}
}
}*_