Below is a video demonstration of the code above. For this piece of code, pitchbend will be most noticeable in instruments with a long sustain, such as a string instrument, keep that in mind when testing the code for yourself.
You will most likely be fine using only 128 steps of pitchbend resolution, but in case you must use all 16384 steps, see the code below. Basically what I've done here is defined a variable called pitchbendVal, which varies from 0 to 16383. As I said below the "zero" pitchbend value is msb = 64 and lsb = 0. In binary this is:
MSB = 64 = 01000000
LSB = 0 = 0000000
(remember MSB and LSB are 7 bit numbers)
putting these values together we get:
which translates to 8192 in decimal
so now the "zero" pitchbend value is 8192.
You'll also notice I had to break the variable pitchbendVal into two 7 bit parts to send out via MIDI message:
MIDImessage(pitchbend, (pitchbendVal&127), (pitchbendVal>>7));
the first part, pitchbendVal&127, returns the least significant 7 bits of pitchbendVal
the second part, pitchbendVal>>7, returns the most significant 7 bits of pitchbendVal
see & and >> on the Arduino reference page for more info.