Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: CC Midi Jumping

  1. #1

    CC Midi Jumping

    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
      }
      
    }

  2. #2
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,402
    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?

  3. #3
    I can't figure out what you actually mean with this:

    Quote Originally Posted by cackland View Post
    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[i]);
    Also, inside the setup {} you have to define the function of the pins as inputs

  4. #4
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    1,402
    Quote Originally Posted by apoikos View Post
    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.

  5. #5
    Quote Originally Posted by oddson View Post
    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.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,072
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •