CCPotentiometer-Map
This is an example of the CCPotentiometer
class of the Control_Surface library, and specifically, how to use the map
function to account for non-linearities of the potentiometer.
The map function in this example corrects for potentiometers that don't go all the way to the extreme values. Some potentiometers still read a value that's greater than 0 when turned all the way to the left. To fix that, tweak the minimumValue
constant. If the potentiometer doesn't read the maximum value when turned all the way to the right, tweak the maximumValue
constant.
- Boards: 🛈
- AVR, AVR USB, Nano Every, Due, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, ESP32, Teensy 3.x
Connections
- A0: wiper of a potentiometer
Connect the left terminal of the potentiometer to ground, and the right one to VCC.
Behavior
- If you open the Serial Monitor, you'll see the raw potentiometer values being printed.
- Turn the potentiometer all the way to the left, and read the value. It should print a value close to zero.
Set minimumValue
to this printed value plus some safety margin (add 5%, for example).
- Now turn the potentiometer all the way to the right, and do the same thing for
maximumValue
.
Mapping
Select the Arduino as a custom MIDI controller in your DAW, and use the MIDI learn option to assign the potentiometer to a function.
It will send the MIDI Control Change Channel Volume parameter for channel 1.
Written by Pieter P, 16-06-2019
https://github.com/tttapa/Control-Surface
constexpr analog_t minimumValue = maxRawValue / 64;
constexpr analog_t maximumValue = maxRawValue - maxRawValue / 64;
analog_t mappingFunction(analog_t raw) {
raw = constrain(raw, minimumValue, maximumValue);
return map(raw, minimumValue, maximumValue, 0, maxRawValue);
}
void setup() {
potentiometer.map(mappingFunction);
Serial.begin(115200);
}
void loop() {
Serial.println(potentiometer.getRawValue());
}
constexpr Channel Channel_1
The main header file that includes all Control-Surface header files.
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
A class of MIDIOutputElements that read the analog input from a potentiometer or fader,...
void begin()
Initialize the Control_Surface.
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
static constexpr analog_t getMaxRawValue()
Get the maximum value that can be returned from getRawValue.
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
constexpr uint8_t Channel_Volume