Hello,
I am running the code below to convert voltage from an expression controller into MIDI messages and send them over a USB connection.
Is there anything wrong with this code? It's compiled with the "Serial + MIDI" USB type option. Then, if I open the serial monitor in the Arduino IDE the dataflow reacts quickly when pushing the pedal. However with the MIDI, I have a latency of around 6 seconds (messages received in Max8 64bit/Windows 10)! I have the same issue on both a Teensy 3.1 and a 3.2.
I am running the code below to convert voltage from an expression controller into MIDI messages and send them over a USB connection.
Is there anything wrong with this code? It's compiled with the "Serial + MIDI" USB type option. Then, if I open the serial monitor in the Arduino IDE the dataflow reacts quickly when pushing the pedal. However with the MIDI, I have a latency of around 6 seconds (messages received in Max8 64bit/Windows 10)! I have the same issue on both a Teensy 3.1 and a 3.2.
Code:
int raw;
int input = A9;
int ctlNumber = 16;
const int channel = 14; // MIDI channel
int MSB, LSB;
#define LED_PIN 13
int older = -1;
void setup() {
analogReadResolution(12);
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
// reset all controllers
usbMIDI.sendControlChange(ctlNumber, 0, channel);
usbMIDI.sendControlChange((ctlNumber+32), 0, channel);
}
void loop() {
// MIDI Controllers should discard incoming MIDI messages.
while (usbMIDI.read()) {
// read & ignore incoming messages
}
raw = analogRead(input);
if (raw != older) {
Serial.print("raw: ");
Serial.print(raw);
MSB = raw >> 7 ;
LSB = raw % 128;
Serial.print(" / MSB : ");
Serial.print(MSB);
Serial.print(" / LSB : ");
Serial.println(LSB);
usbMIDI.sendControlChange(ctlNumber, MSB, channel);
usbMIDI.sendControlChange((ctlNumber+32), LSB, channel);
older = raw;
}
}