Send midi pitch bend with a joystick

Verify first that your joystick does give you a full range between 0 and 1023 and 512 in the middle, when idle

If so then try this code

void loop() {
  int analogValue = analogRead(A0) - 512; // 0 at mid point
  if ( abs(analogValue-lastAnalogValue) > 1)  { // have we moved enough to avoid analog jitter?
    if ( abs(analogValue) > 4) { // are we out of the central dead zone?
      MIDI.sendPitchBend(8*analogValue, 1); // or -8 depending which way you want to go up and down 
      lastAnalogValue = analogValue;
    }
  }
}

Note that you can pass something between -8192 (maximum downwards bend) and 8191 (max upwards bend) and center value is 0. As we have a analogValue Between -512 and +511, multiplying by 8 just gives you half the range. You could multiply by 16 if you want

(Typed here from my mobile so totally untested)

1 Like