Well I got it to work using this code.
byte incomingByte;
byte note;
byte velocity;
byte check;
int statusLed = 13;
void setup()
{
//start serial with midi baudrate 31250 or 38400 for debugging
Serial.begin(31250);
digitalWrite(statusLed, HIGH);
}
void loop ()
{
if (Serial.available() > 0)
{
incomingByte = Serial.read();
delayMicroseconds(400);
if (incomingByte== 144)
{
note = Serial.read();
delayMicroseconds(400);
velocity = Serial.read();
while (check!= 128 )
{
check = Serial.read();
freqout(note);
}
}
check=0;
}
}
void freqout(int freq)
{
int hperiod;
hperiod = (500000 / (freq*2));
analogWrite(12, 255);
delayMicroseconds(hperiod);
digitalWrite(12, LOW);
delayMicroseconds(hperiod-1);
}
But it only works if I send midi from live on my computer. If i try to use my keyboard controller it will triger a note and the just hold it on forever shrug
Also I had to use the micro second delays to read the serial info, but now if I have 2 note trigger right next to the other it will miss the second one, I assume due to the delay.