Pages: [1]   Go Down
Author Topic: MIDI Controller - Potentiometer Eratic/No Data  (Read 955 times)
0 Members and 1 Guest are viewing this topic.
Stafford, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 18
:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


Code:
// 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.


* Screen Shot 2013-03-05 at 17.20.39.png (47.71 KB, 729x383 - viewed 32 times.)
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1614
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That code doesn't compile. This statement doesn't make sense:
Code:
    if ( abs(cc !=LastAV[x]) {

Change it to:
Code:
    if (cc !=LastAV[x]) {

Pete
Logged

Where are the Nick Gammons of yesteryear?

Stafford, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 18
:)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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? smiley-sad
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1614
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try changing this:
Code:
byte midiCCselect[2] = {20,21};
to this:
Code:
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
Logged

Where are the Nick Gammons of yesteryear?

Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you can try is defining te analogPins, like this:
Code:
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
Code:
int analogPin[2] = {A0, A1};
and edited the analogRead section.

Logged

Sorry about my English, I'm a Dutchman!

Pages: [1]   Go Up
Jump to: