/* The idea of this progam is to serve as a bridge between USB MIDI and Serial MIDI. To this end midi messages arriving on the serial MIDI are passed through to the USB MIDI and vice versa. By default te Teensy 3.2 Serial1 interface is used to interface with Serial MIDI. This is found on ports 0 to receive and 1 to transmit. FYI Serial2 is found on ports 9 and 10, Serial3 on ports 7 and 8. A current limitation is that only 3 byte midi messages are passed throug, sysex messages are blocked! */ #include #include const int PERIOD_IN_MICROS = 200000;//200 ms const int EVENT_DURATION_IN_MILLIS = 100; volatile bool newEvent = false; //timer for the measurements IntervalTimer eventTimer; elapsedMicros timeForResponse; MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI_NEXT); const int ledPin = LED_BUILTIN; void setEventBoolean(){ newEvent = true; } void setup() { MIDI_NEXT.begin(); Serial.begin(115200); Serial.println("MIDI roundtrip latency test"); pinMode(ledPin, OUTPUT); // Blink LED at startup digitalWrite(ledPin, HIGH); delay(400); digitalWrite(ledPin, LOW); delay(400); digitalWrite(ledPin, HIGH); delay(400); digitalWrite(ledPin, LOW); eventTimer.begin(setEventBoolean, PERIOD_IN_MICROS); } void loop() { if(newEvent){ newEvent=false; timeForResponse = 0; MIDI_NEXT.sendNoteOn(69, 120, 1); digitalWrite(ledPin,!digitalRead(ledPin)); } // Send incoming USB midi data to hardware midi while (MIDI_NEXT.read()) { Serial.print(timeForResponse); Serial.println(" microseconds for response"); } }