PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

86 rindas
2.2KB

  1. #include <MIDI.h>
  2. // This program will measure the time needed to receive, parse and process a
  3. // NoteOn message.
  4. // For it to work, please connect RX and TX on the MIDI port:
  5. // Due, Leonardo and other USB-native Arduinos: Serial1
  6. // All other Arduinos: Connect pins 2 and 3.
  7. // The program will then wait for 100 loops and print the results.
  8. #if defined(ARDUINO_SAM_DUE) || defined(USBCON)
  9. // Print through USB and bench with Hardware serial
  10. MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiBench);
  11. #else
  12. #include <SoftwareSerial.h>
  13. SoftwareSerial midiSerial(2,3);
  14. MIDI_CREATE_INSTANCE(SoftwareSerial, midiSerial, midiBench);
  15. #endif
  16. // -----------------------------------------------------------------------------
  17. unsigned long gTime_start = 0;
  18. unsigned long gTime_stop = 0;
  19. unsigned gCounter = 0;
  20. unsigned long gTime_sum = 0;
  21. unsigned long gTime_min = -1;
  22. unsigned long gTime_max = 0;
  23. // -----------------------------------------------------------------------------
  24. void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
  25. {
  26. gTime_stop = micros();
  27. const unsigned long diff = gTime_stop - gTime_start;
  28. gTime_sum += diff;
  29. if (diff > gTime_max) gTime_max = diff;
  30. if (diff < gTime_min) gTime_min = diff;
  31. if (gCounter++ >= 1000)
  32. {
  33. const unsigned long average = gTime_sum / (float)gCounter;
  34. Serial.println("Time to receive NoteOn: ");
  35. Serial.print("Average: ");
  36. Serial.print(average);
  37. Serial.println(" microsecs");
  38. Serial.print("Min: ");
  39. Serial.print(gTime_min);
  40. Serial.println(" microsecs");
  41. Serial.print("Max: ");
  42. Serial.print(gTime_max);
  43. Serial.println(" microsecs");
  44. gCounter = 0;
  45. gTime_sum = 0;
  46. gTime_max = 0;
  47. gTime_min = -1;
  48. midiBench.turnThruOff();
  49. }
  50. }
  51. // -----------------------------------------------------------------------------
  52. void setup()
  53. {
  54. midiBench.setHandleNoteOn(handleNoteOn);
  55. midiBench.begin();
  56. Serial.begin(115200);
  57. while(!Serial);
  58. Serial.println("Arduino Ready");
  59. midiBench.sendNoteOn(69,127,1);
  60. }
  61. void loop()
  62. {
  63. gTime_start = micros();
  64. midiBench.read();
  65. }