Aussie_CrocHunter
Well-known member
Hi, I'm adding an expression pedal port to me midistomp pedal so I've done a little test sketch based on an analog pot example sketch. I know some expression pedals are inverted, some have a polarity switch, and some don't.
Two questions:
1. Is there are better way to write this code? (don't want it to be too messy)
2. Can you show me how to make a user-editable 'virtual polarity switch' which will invert the midi range so it would read 127 to 0 OR 0 to 127 ?
Thank you
Two questions:
1. Is there are better way to write this code? (don't want it to be too messy)
2. Can you show me how to make a user-editable 'virtual polarity switch' which will invert the midi range so it would read 127 to 0 OR 0 to 127 ?
Thank you
Code:
#include <Bounce.h>
// the MIDI channel number to send messages
const int channel = 1;
// the MIDI continuous controller for each analog input
const int controllerA10 = 98;
void setup() {
}
// store previously sent values, to detect changes
int previousA0 = -1;
elapsedMillis msec = 0;
void loop() {
// only check the analog inputs 50 times per second,
// to prevent a flood of MIDI messages
if (msec >= 20) {
msec = 0;
int n0 = analogRead(A10) / 8;
// only transmit MIDI messages if analog input changed
if (n0 != previousA0) {
usbMIDI.sendControlChange(controllerA10, n0, channel);
previousA0 = n0;
}
}
while (usbMIDI.read()) {
// ignore incoming messages
}
}