Problems with MIDI pots

Hello everyone,I’m trying to make a MIDI controller with an Arduino Uno R3 and two rotary pots.I’m kind of a newb so I’m sure I effed up somewhere, and I keep getting the ‘‘MIDI’ was not declared in this scope’’ error.Can anyone help?

// include MIDI library
#include <MIDI.h>

// read potentiometer value
int analogValue = 0;
// maximum MIDI value is 127, first/previous potentiometer
// move has to always be different than previous value
int lastAnalogValue = 128;

void setup() {
MIDI.begin(4);
// 115200 hairless MIDI
Serial.begin(115200);
}

void loop() {

// Analog potentiometer

// potentiometer gives values up to 1023
// we need values not bigger than 127
int analogValue = analogRead(A0) / 8;

// potentiometer could be too sensitive and
// give different (±1) values.
// send CC only when the difference between last value
// is more than 1
if ((analogValue - lastAnalogValue) > 1 || (analogValue - lastAnalogValue) < -1) {
// value changed?
if (analogValue != lastAnalogValue) {
// send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
MIDI.sendControlChange(1, analogValue, 1);
lastAnalogValue = analogValue;
}
}

delay(1);
}

That's because you have left out the MIDI create. See the examples that come with the library. You may just want

MIDI_CREATE_DEFAULT_INSTANCE();

but you should check because there are other variations depending on what board you're using and how the MIDI is connected (USB / 5-pin DIN etc).

Steve

You might be interested in my MIDI Controller library.

Pieter

  if ((analogValue - lastAnalogValue) > 1 || (analogValue - lastAnalogValue) < -1) {
    // value changed?
    if (analogValue != lastAnalogValue) {
      // send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
      MIDI.sendControlChange(1, analogValue, 1);
      lastAnalogValue = analogValue;
    }
  }

Note: You don’t have to check to see if the new value is different from the old value AFTER you have just determined they are different by at least 1. This version is simpler and does the same thing:

  if ((analogValue - lastAnalogValue) > 1 || (analogValue - lastAnalogValue) < -1) {
      // send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
      MIDI.sendControlChange(1, analogValue, 1);
      lastAnalogValue = analogValue;
  }