CC Midi Jumping

Status
Not open for further replies.

cackland

Well-known member
Hi Guys,

I have set up a simple 8 fader controller, using the code below.

However, when i assign the midi cc to a software parameter, it seems to jump between the fader cc's.

Any idea of why this is happening?

Thanks in advance.

Corey

Code:
// define how many pots are active up to number of available analog inputs
#define analogInputs 2
// make arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// make array of cc values
int ccValue[analogInputs];
// index variable for loop
int i;
int ccs[] = {1,11,7,30,25,64,3,4};

void setup() {
  

}

void loop() {
  // loop trough active inputs for knobs
  for (i=0;i<analogInputs;i++){
    // read current value at i-th input
    inputAnalog[i] = analogRead(i);
    // if magnitude of difference is 8 or more...
    if (abs(inputAnalog[i] - iAlag[i]) > 7){
      // calc the CC value based on the raw value
      ccValue[i] = inputAnalog[i]/8;
      // send the MIDI
      usbMIDI.sendControlChange(ccs[i], ccValue[i], 1);
      // set raw reading to lagged array for next comparison
      iAlag[i] = inputAnalog[i];
    }
  delay(5); // limits MIDI messages to reasonable number
  }
  
}
 
Could you give a more precise description of the problem?

Do you mean there is spurious output from more than one pin when nothing is moved?

If so, does increasing the change threshold from >7 to say >15 make it stop?
 
I can't figure out what you actually mean with this:

However, when i assign the midi cc to a software parameter, it seems to jump between the fader cc's.

Anyway at first glance your code has two issues. First, you are reading only 2 analog signals (the loop goes from 0 to 1) and you are telling analogread() to read the pins 0 and 1 (because when you put "i" the loop substitutes it with the current i value) which are actually digital pins and not analog pins. Where have you connected your pots to? Which pins?
You should define the pins you are attaching the pots to in another vector such as Pots[] = {20,21};
and the inside the loop you write analogRead(Pots);
Also, inside the setup {} you have to define the function of the pins as inputs
 
I can't figure out what you actually mean with this:



Anyway at first glance your code has two issues. First, you are reading only 2 analog signals (the loop goes from 0 to 1) and you are telling analogread() to read the pins 0 and 1 (because when you put "i" the loop substitutes it with the current i value) which are actually digital pins and not analog pins. Where have you connected your pots to? Which pins?
analogRead (0) reads analog pin 0. So the code is reading pins 14 and 15 on a T3.x.

The code is very old... I wrote it as a fix to Phillip Cunningham's example code from the usbMIDI page (now a dead link). It worked with Teensy 2.0 well enough but it was written in the first few days of my getting my first teensy. Despite my inexperience I managed a passable hysteresis method to replace his faulty averaging system so he pulled my changes into git hub. The use of delay is not ideal but works.
 
analogRead (0) reads analog pin 0. So the code is reading pins 14 and 15 on a T3.x.

I had no idea really, where is it in the docs? I never tried that specifically but if i do analogRead(14) it reads A0 not A14, hence my thought.
 
It's pretty much a legacy Arduino compatibility feature. Using numbers 0 to 5 to read analog A0 to A5 is widely documented on (mostly very old) tutorials on many websites.

On 32 bit Teensy boards, 0 to 13 read analog pins A0 to A13. But for A14 and higher, you have to use the actual PIN numbers, or the names which are just the actual pin numbers.
 
Status
Not open for further replies.
Back
Top