Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: MIDI benchmark sketch compatible with Teensy LC?

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Posts
    11

    MIDI benchmark sketch compatible with Teensy LC?

    Is it possible to use this MIDI benchmark sketch below with a Teensy LC?

    It does not currently include definitions for ARM boards but I do see this issue here where it looks like there needs to be a modification of the conditions:

    Code:
    #if defined(SERIAL_PORT_USBVIRTUAL) || defined(ARDUINO_SAM_DUE) || defined(USBCON)
    Is that all it would need to work for a Teensy LC?

    Here is the current sketch:

    Code:
    #include <MIDI.h>
    
    // This program will measure the time needed to receive, parse and process a
    // NoteOn message.
    // For it to work, please connect RX and TX on the MIDI port:
    // Due, Leonardo and other USB-native Arduinos:     Serial1
    // All other Arduinos:                              Connect pins 2 and 3.
    // The program will then wait for 100 loops and print the results.
    
    #if defined(ARDUINO_SAM_DUE) || defined(USBCON)
        // Print through USB and bench with Hardware serial
        MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiBench);
    #else
        #include <SoftwareSerial.h>
        SoftwareSerial midiSerial(2,3);
        MIDI_CREATE_INSTANCE(SoftwareSerial, midiSerial, midiBench);
    #endif
    
    // -----------------------------------------------------------------------------
    
    unsigned long gTime_start = 0;
    unsigned long gTime_stop  = 0;
    unsigned gCounter = 0;
    unsigned long gTime_sum   = 0;
    unsigned long gTime_min   = -1;
    unsigned long gTime_max   = 0;
    
    // -----------------------------------------------------------------------------
    
    void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
    {
        gTime_stop = micros();
    
        const unsigned long diff = gTime_stop - gTime_start;
        gTime_sum += diff;
    
        if (diff > gTime_max) gTime_max = diff;
        if (diff < gTime_min) gTime_min = diff;
    
        if (gCounter++ >= 1000)
        {
            const unsigned long average = gTime_sum / (float)gCounter;
    
            Serial.println("Time to receive NoteOn: ");
    
            Serial.print("Average: ");
            Serial.print(average);
            Serial.println(" microsecs");
    
            Serial.print("Min:     ");
            Serial.print(gTime_min);
            Serial.println(" microsecs");
    
            Serial.print("Max:     ");
            Serial.print(gTime_max);
            Serial.println(" microsecs");
    
            gCounter = 0;
            gTime_sum = 0;
            gTime_max = 0;
            gTime_min = -1;
    
            midiBench.turnThruOff();
        }
    }
    
    // -----------------------------------------------------------------------------
    
    void setup()
    {
        midiBench.setHandleNoteOn(handleNoteOn);
        midiBench.begin();
    
        Serial.begin(115200);
        while(!Serial);
        Serial.println("Arduino Ready");
    
        midiBench.sendNoteOn(69,127,1);
    }
    
    void loop()
    {
        gTime_start = micros();
        midiBench.read();
    }

  2. #2
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    162
    Just did this, nicked from another project for T3.2, T3.5 and T3.6, tested working on a T3.2.

    Code:
    #if defined(ARDUINO_SAM_DUE) || defined(USBCON)  || (__MK20DX256__)|| (__MK64FX512__) || (__MK66FX1M0__)
    You would probably make that:-

    Code:
    #if defined(ARDUINO_SAM_DUE) || defined(USBCON)  || (__MKL26Z64__) || (__MK20DX256__)|| (__MK64FX512__) || (__MK66FX1M0__)
    To cover the Teensy LC as well

  3. #3
    Junior Member
    Join Date
    Oct 2020
    Posts
    11
    You would probably make that:-

    Code:
    Code:
    #if defined(ARDUINO_SAM_DUE) || defined(USBCON)  || (__MKL26Z64__) || (__MK20DX256__)|| (__MK64FX512__) || (__MK66FX1M0__)
    To cover the Teensy LC as well
    Excellent - thank you! I just tested it and it worked with no issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •