Pitch Bend pots with individual map ranges? #483
-
I'm cutting/pasting bits and pieces from the various examples provided, but am a bit stuck figuring out the 'correct' way to have a few pots, each on their own Pitch Bend channel, each needing their own individually remapped ranges. Once I've got that sorted, I'll be adding a multiplexer to up the total to about 15 pots per board. I wonder if that will throw in new challenges... Any help very much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
This is my current sketch: #include <Control_Surface.h>
USBMIDI_Interface midi;
PBPotentiometer potentiometer01 = {
A0,
CHANNEL_1,
};
PBPotentiometer potentiometer02 = {
A1,
CHANNEL_2,
};
constexpr analog_t minimumValue01 = 10000;
constexpr analog_t maximumValue01 = 12000;
constexpr analog_t minimumValue02 = 8000;
constexpr analog_t maximumValue02 = 14000;
analog_t mappingFunction01(analog_t raw) {
raw = constrain(raw, minimumValue01, maximumValue01);
return map(raw, minimumValue01, maximumValue01, 0, 16383);
}
analog_t mappingFunction02(analog_t raw) {
raw = constrain(raw, minimumValue02, maximumValue02);
return map(raw, minimumValue02, maximumValue02, 0, 16383);
}
void setup() {
potentiometer01.map(mappingFunction01);
potentiometer02.map(mappingFunction02);
Control_Surface.begin();
}
void loop() {
Control_Surface.loop();
Serial.println(potentiometer01.getRawValue());
Serial.println(potentiometer02.getRawValue());
} It works, but is obviously going to get quite big as I add more potentiometers. Possible to make it more efficient? |
Beta Was this translation helpful? Give feedback.
-
You could use something like this: #include <Control_Surface.h>
USBMIDI_Interface midi;
PBPotentiometer potentiometers[] = {
{ A0, CHANNEL_1, },
{ A1, CHANNEL_2, },
};
template <analog_t MinVal, analog_t MaxVal>
analog_t mappingFunction(analog_t raw) {
raw = constrain(raw, MinVal, MaxVal);
return map(raw, MinVal, MaxVal, 0, FilteredAnalog<>::getMaxRawValue());
}
void setup() {
potentiometers[0].map(mappingFunction<10000, 12000>);
potentiometers[1].map(mappingFunction<8000, 14000>);
Control_Surface.begin();
}
void loop() {
Control_Surface.loop();
} |
Beta Was this translation helpful? Give feedback.
-
Agreed. Wondering - can the values passed to the mappingFunction be variables? I am having trouble doing this, getting the error message:
|
Beta Was this translation helpful? Give feedback.
You could use something like this: