sending MIDI pitchbend data

Hello,

I'm building a MicroKORG-based key-tar, using an Arduino to parse data from sensors on the neck and sending them as MIDI data into the MicroKORG.

I can send modwheel and CC values fine, but I'm having trouble sending pitch bend data. Pitchbend data is sent as 3 MIDI serial bytes: first byte: E0 for channel 1, or 224. second byte: most significant byte of the pitch bend data third byte: least significant byte of pitch bend data.

The pitch bend data is 14-bit, I believe. Each bit is 0-127. My questions is how to interpret an analog controller (range 0-1023) and split it up/map it to two 7-bit MIDI bytes.

Here's some simple code that I'd use: Serial.print(224, BYTE); Serial.print(pitchMSB, BYTE); Serial.print(pitchLSB, BYTE);

Any help is appreciated. Thanks! -Drew

The problem is that your code splits it up into byte values where as MIDI requires the maximum number to be 127. You need something like this:-

val = analogRead(pin);
Serial.print(224, BYTE);
Serial.print((val >> 7), BYTE);
Serial.print(val & 0x7F, BYTE);