MIDI Controller - Potentiometer Eratic/No Data

Hi everyone,

I am currently building a MIDI controller using the Arduino Uno.

I wrote a code using MIDI Control Change messages to allow one pot to be assigned to a parameter within a Digital Audio Workstation. This has worked great.

I have now tried to extend this code to add another pot. The pot either gives eratic data or does not respond at all.

I have posted copies of both my code and the circuit layout (I'm pretty new to both these things, so please forgive me if they are not brilliant!)

I have searched this forum for previous topics and come across some help, but I'm still extremely stuck.

// Variables:
int input_nb = 2;                       // number of analog inputs
int AV[2] = {0,0};                      // define variables for the controller data
byte LastAV[2] = {0,0};                 // define the last value variables
byte midiCCselect[2] = {20,21};         // MIDI controller number (20-31 undefined) this is good for adding extra inputs later on.
byte thresh[2] = {1,1};                 // select threshold for each analog input

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250); // 31250
}

void loop() {
  for (int x =0; x < input_nb; x++) {     // initialisation; condition; increment           

    //  Pot value = 1023
    AV[x] = analogRead(x);

    // Divide this value so it equals 127 (for MIDI)
    int cc = AV[x]/8;

    // If the Control Change is not equal to the last analog value, then send a MIDI CC:
    if ( abs(cc !=LastAV[x]) {

      //MIDI Control Change
      midiCC(0xB0, midiCCselect[x], cc);

      // The last value read becomes the new value for the next if statement:
      LastAV[x] = cc;
    }

  }  
}

// sends a Midi CC. 
void midiCC(byte CC_data, byte c_num, byte c_val){
  Serial.write((byte)CC_data);
  Serial.write((byte)c_num);
  Serial.write((byte)c_val);
}

Any help would be appreciated.

That code doesn't compile. This statement doesn't make sense:

    if ( abs(cc !=LastAV[x]) {

Change it to:

    if (cc !=LastAV[x]) {

Pete

Thanks for the reply. I have tried this but still no luck. The first pot (controller number 20) works but the second pot does not. Any other ideas? :frowning:

Try changing this:

byte midiCCselect[2] = {20,21};

to this:

byte midiCCselect[2] = {21,20};

If the first pot is working, this should make it use CC 21 instead of 20 and it should work with 21.

Pete

What you can try is defining te analogPins, like this:

int analogPin[2] = {A0, A1}; //Defining the analog pins

// Variables:
int input_nb = 2;                       // number of analog inputs
int AV[2] = {0,0};                      // define variables for the controller data
byte LastAV[2] = {0,0};                 // define the last value variables
byte midiCCselect[2] = {20,21};         // MIDI controller number (20-31 undefined) this is good for adding extra inputs later on.
byte thresh[2] = {1,1};                 // select threshold for each analog input

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250); // 31250
}

void loop() {
  for (int x =0; x < input_nb; x++) {     // initialisation; condition; increment           

    //  Pot value = 1023
    AV[x] = analogRead(analogPin[x]); // readout the analogPin

    // Divide this value so it equals 127 (for MIDI)
    int cc = AV[x]/8;

    // If the Control Change is not equal to the last analog value, then send a MIDI CC:
    if (cc !=LastAV[x]) {

      //MIDI Control Change
      midiCC(0xB0, midiCCselect[x], cc);

      // The last value read becomes the new value for the next if statement:
      LastAV[x] = cc;
    }

  }  
}

// sends a Midi CC. 
void midiCC(byte CC_data, byte c_num, byte c_val){
  Serial.write((byte)CC_data);
  Serial.write((byte)c_num);
  Serial.write((byte)c_val);
}

You see I add, a

int analogPin[2] = {A0, A1};

and edited the analogRead section.