tttapa / MIDI_controller

This is a library for creating a MIDI controller using an Arduino or Teensy board.
GNU General Public License v3.0
403 stars 70 forks source link

Calibrating a potentiometer #50

Closed mikereynoldss closed 6 years ago

mikereynoldss commented 6 years ago

Hey dude

I'm having some problems calibrating a potentiometer. Some guy online helped me with the code but I can't get it to work. Do you think this is not supported by the library?

Here is the code I used:

#include <MIDI_Controller.h>

AnalogMultiplex multiplexerF(A13, {34, 35, 36, 37} );
Analog potentiometersF[] = {
  { multiplexerF.pin(12), 0x1, 2 },
};

int potentiometerCalibrate(int val) {

  if (val <= 44)
  {
    return map(val, 0, 44, 0, 255);
  }
  if (val > 44 && val < 975)
  {
    return map(val, 45, 974, 255, 767);
  }
  if (val >= 975 )
  {
    return map(val, 975, 1023, 767, 1023);
  }

}

void setup() {
    potentiometersF[0].map(potentiometerCalibrate);
  }
void loop() {
  MIDI_Controller.refresh();
}

And here is the potentiometer curve (the blue one, ignore the others):

y axis is analog value and x axis is % of slide.

tttapa commented 6 years ago

That code compiles just fine for me. Mappings like that are supported by the library.

mikereynoldss commented 6 years ago

The code is compiling to me too. But when I upload it and plug the MIDI device in, my software even recognizes two potentiometers and is working awfully. Do you think the code could be done in a different way?

tttapa commented 6 years ago

Define "working awfully"?

mikereynoldss commented 6 years ago

The values only change from 0 and 1% on my fader and half of the potentiometer does nothing

tttapa commented 6 years ago

I tested it myself on a Teensy 3.2 (without a mutliplexer), and it works just as expected, so I suspect that there's something wrong with your wiring.

mikereynoldss commented 6 years ago

Yeah I checked my cabling and its working now. Thanks a bunch