PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

52 líneas
1.6KB

  1. #include <MIDI.h>
  2. MIDI_CREATE_DEFAULT_INSTANCE();
  3. // -----------------------------------------------------------------------------
  4. // This function will be automatically called when a NoteOn is received.
  5. // It must be a void-returning function with the correct parameters,
  6. // see documentation here:
  7. // https://github.com/FortySevenEffects/arduino_midi_library/wiki/Using-Callbacks
  8. void handleNoteOn(byte channel, byte pitch, byte velocity)
  9. {
  10. // Do whatever you want when a note is pressed.
  11. // Try to keep your callbacks short (no delays ect)
  12. // otherwise it would slow down the loop() and have a bad impact
  13. // on real-time performance.
  14. }
  15. void handleNoteOff(byte channel, byte pitch, byte velocity)
  16. {
  17. // Do something when the note is released.
  18. // Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
  19. }
  20. // -----------------------------------------------------------------------------
  21. void setup()
  22. {
  23. // Connect the handleNoteOn function to the library,
  24. // so it is called upon reception of a NoteOn.
  25. MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function
  26. // Do the same for NoteOffs
  27. MIDI.setHandleNoteOff(handleNoteOff);
  28. // Initiate MIDI communications, listen to all channels
  29. MIDI.begin(MIDI_CHANNEL_OMNI);
  30. }
  31. void loop()
  32. {
  33. // Call MIDI.read the fastest you can for real-time performance.
  34. MIDI.read();
  35. // There is no need to check if there are messages incoming
  36. // if they are bound to a Callback function.
  37. // The attached method will be called automatically
  38. // when the corresponding message has been received.
  39. }