echoing midi signal

so basically i have made a midi keyboard with 16 keys, however in order to transfer the clock through it i need it to havee a midi in to send the midi clock and whatever midi messages there are straight through, merely adding the keyboard messages to the existing midi.

right now it only acts as having midi out, as i was going to merge the signals after, however if this solution is possible it would vastly simplify the circuit.

any help would be very much appreciated!!! :slight_smile:

int HotPin[4] = {6,3,4,5}; //Hot (output) pins //got pins wrong way round
int GndPin[4] = {6,5,4,3}; //Ground (input) pins //
int OldKeyPress[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //
int NewKeyPress[24] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //
int KeyNum = 1; //Identifies the key being read //
int MidiNote = 60; //The MIDI note to be played (Middle C is 60)
int midnote; // the midi note automatically transposed to

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

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

}

void loop()

{

for (int h=0; h <= 3; h++)
{
digitalWrite(HotPin, HIGH);
{
for (int g=0; g <=3; g++)
{
KeyNum = (h * 4) + g; //Sets KeyNum to a value from 0 to 31 (C1 is 04)
if(analogRead(GndPin[g]) >= 600)
{
NewKeyPress[KeyNum] = 1;
}
else
{
NewKeyPress[KeyNum] = 0;
}
//Find out if the key if pressed
MidiNote = KeyNum + 36; //makes first button C1
if (NewKeyPress[KeyNum] == 1 && OldKeyPress[KeyNum] == 0) //If key is pressed
{
MidiMessage(0x90 + midnote, MidiNote, 0x70); //note on, channel 1
}
else if (NewKeyPress[KeyNum] == 0 && OldKeyPress[KeyNum] == 1) //If key is released
{
MidiMessage(0x80 + midnote, MidiNote, 0x70); //note off, channel 1
}
OldKeyPress[KeyNum] = NewKeyPress[KeyNum]; //Set state for next check
}
}
digitalWrite(HotPin, LOW);
}
}

//=================================================================================================
void MidiMessage(char cmd, char data1, char data2) //
{ //
Serial.write(byte(cmd)); //
Serial.write(byte(data1)); //
Serial.write(byte(data2)); //
} //
//=================================================================================================

[/td]
[/tr]
[/table]