39 lines
978 B
Markdown
39 lines
978 B
Markdown
# CCPotentiometer Map
|
|
|
|
Analog input with a custom mapping function to eliminate dead zones.
|
|
|
|
> Original: `CCPotentiometer-Map.ino`
|
|
|
|
```cpp pico
|
|
#include "pico/stdlib.h"
|
|
#include "pico/cyw43_arch.h"
|
|
#include <cs_midi.h>
|
|
|
|
using namespace cs;
|
|
|
|
BluetoothMIDI_Interface midi;
|
|
|
|
CCPotentiometer potentiometer {26, {MIDI_CC::Channel_Volume, Channel_1}};
|
|
|
|
constexpr analog_t maxRawValue = CCPotentiometer::getMaxRawValue();
|
|
constexpr analog_t minimumValue = maxRawValue / 64;
|
|
constexpr analog_t maximumValue = maxRawValue - maxRawValue / 64;
|
|
|
|
analog_t mappingFunction(analog_t raw) {
|
|
if (raw < minimumValue) raw = minimumValue;
|
|
if (raw > maximumValue) raw = maximumValue;
|
|
return (raw - minimumValue) * maxRawValue / (maximumValue - minimumValue);
|
|
}
|
|
|
|
int main() {
|
|
stdio_init_all();
|
|
if (cyw43_arch_init()) return 1;
|
|
potentiometer.map(mappingFunction);
|
|
Control_Surface.begin();
|
|
while (true) {
|
|
Control_Surface.loop();
|
|
sleep_ms(1);
|
|
}
|
|
}
|
|
```
|