Need help with MIDI library Pitchbend.

I posted this on hardware forum accidentally. So please look there

But the main point is I cant figure pitchbend with MIDI lib,
I get error
o: In function loop': undefined reference to MIDI_Class::sendPitchBend(int, unsigned char)’
with simple test code

#include <MIDI.h>
byte note = 0;
byte val = 0;
int AnalogValue = 5;

void setup() {

  MIDI.sendProgramChange (12,1);

void loop() {
    val = analogRead(0);

Do you mean .sendPitchChange?

Well i try to use this midi library And from reference I get that only MIDI.sendPitchBend((int PitchValue,byte Channel) is needed.

It's just that "undefined reference" usually is a typo.

Strange! Even when copy/paste from the reference list I get the same.

If you had pasted the entire error message, you would have saved me a bunch of work. This line:


generates this error message:

o: In function loop': C:\DOCUME~1\pjs9486\LOCALS~1\Temp\build7524100004304053010.tmp/MIDI_Basic_IO.cpp:20: undefined reference toMIDI_Class::sendPitchBend(int, unsigned char)'

There are number of ways that the 2nd argument in your call can be interpreted. The error message is saying that the compiler interpreted the argument as an unsigned char, and did not find a function in the MIDI library with the name sendPitchBend that takes and int and an unsigned char as input arguments.

There is a method in the library with the name sendPitchBend that takes an int and a byte. If you put the value 1 in a variable of type byte, or cast the 1 to a byte, the compiler will find the correct function:

   MIDI.sendPitchBend(val, (byte)1);

Sorry I had no clue that there was more to the error message. I am rather new to this and writing a code is so alien to me.

However if I just replace my code with your code I get nowhere. Could you show the whole code that works so I could study and learn - I understand picture way better than text. Thanks!

I am trying to get analog input (a pot) to control PitchBend value on channel 1.

I got the same error message you got, with your code, and thought I understood what it was complaining about. I was wrong.

A closer inspection reveals that setPitchBend is defined in the header file, but is not implemented in the source code. Time to contact the library author and kick some rear end, I think. Publishing incomplete, untested libraries is in-excusable.

Very well found PaulS

Now I an even more sorry. This was a bug in the library that is corrected by the author now and all works well. I really like this midi lib - it is simple and understandable. Thanks all you helped!