Teensy Resolution

Status
Not open for further replies.

cackland

Well-known member
Hey Guys,

Using this code, I can assign and control 8 faders (potentiometers) to for MIDI CC messages.

I've tested it, works fine, however noticed that it skips 3 - 4 steps of 127 midi resolution. So when I pull down the fader from 127, i'm moving the fader slowly and the next value it displays would be 123 for example. So it's almost like its not fine tune enough.

Can any help on how I would fix this so that when i pull the fader, it accounts for each and every 1 value.

Appreciate any help.

Here is the code:
HTML:
// define how many pots are active up to number of available analog inputs
#define analogInputs 8
// make arrays for input values and lagged input values
int inputAnalog[analogInputs];
int iAlag[analogInputs];
// make array of cc values
int ccValue[analogInputs];
//analog inputs to be read in the loop
const int pintable [analogInputs] ={A0, A1 , A2, A3, A4, A5, A6, A7};
//controller numbers to which these inputs will be mapped
const int controldest [analogInputs] = {25, 24, 23, 22, 2, 7, 11, 1};
// index variable for loop
int i;

//The setup function is called once at startup of the sketch
void setup()
{
// Add your initialization code here
  // MIDI rate
  Serial.begin(31250);
  delay(5000); //give me the time to launch the midi monitor
}

// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here
  // loop trough active inputs
  for (i=0;i<analogInputs;i++){
    // read current value at i-th input
    inputAnalog[i] = analogRead(pintable[i]);
    // if magnitude of difference is 8 or more...
    if (abs(inputAnalog[i] - iAlag[i]) > 23){
      // calculate the CC value based on the raw value
        ccValue[i] = inputAnalog[i]/8;
        // send the MIDI
        usbMIDI.sendControlChange(controldest[i], ccValue[i], 1);
        // set raw reading to lagged array for next comparison
        iAlag[i] = inputAnalog[i];
    }
  }
  while (usbMIDI.read()) {
  }
  delay(18); // limits MIDI messages to reasonable number
}
 
I've tested it, works fine, however noticed that it skips 3 - 4 steps of 127 midi resolution.

Maybe it's related to this code:

Code:
    inputAnalog[i] = analogRead(pintable[i]);
    // if magnitude of difference is 8 or more...
    if (abs(inputAnalog[i] - iAlag[i]) > 23){
      // calculate the CC value based on the raw value
        ccValue[i] = inputAnalog[i]/8;
        // send the MIDI
        usbMIDI.sendControlChange(controldest[i], ccValue[i], 1);
        // set raw reading to lagged array for next comparison
        iAlag[i] = inputAnalog[i];

Seems you're intentionally ignoring changes smaller than 23 ADC steps, no matter how long or stable the 1-23 change is.

After dividing by 8, that corresponds very well with the "skips 3 - 4 steps" issue you're seeing after the MIDI messages arrive.
 
Status
Not open for further replies.
Back
Top