MIDI Library Reading Pitch Bend (Not Send)

Here is the code.

I will give an explanation of what I am trying to do.

I use the Tone library to play three different tones.

I am using the MIDI library to read MIDI notes. When a MIDI note is read, the code sets the frequency for the three different tones.

Now I am trying to add in something to read the pitch bend. I want it to work like it usually does on a synth (bends up or down two semitones, returns to 0 when released, if the pitch bend is held then the next note pressed starts the tone with the bent pitch value, if you increase it to full and lower it halfway back down then the frequency of the tones follow it up to two semitones and back down to one semitone).

I was trying to reset it to 0 using the else{bend = 0;} in the HandlePitchBend function.

Next will be reading MIDI clock and sending out ON/OFF pulses. I hope that is possible too.

Thanks for your help.