Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #include <MIDI.h>
  2.  
  3. MIDI_CREATE_DEFAULT_INSTANCE();
  4. //MIDI_CREATE_INSTANCE(HardwareSerial, Serial1,MIDI);
  5. int cnt=1;
  6.  
  7.  
  8.  
  9. // -----------------------------------------------------------------------------
  10.  
  11. // This function will be automatically called when a NoteOn is received.
  12. // It must be a void-returning function with the correct parameters,
  13. // see documentation here:
  14. // http://arduinomidilib.fortyseveneffects.com/a00022.html
  15.  
  16. void handleNoteOn(byte channel, byte pitch, byte velocity)
  17. {
  18. // Do whatever you want when a note is pressed.
  19. cnt+=1;
  20. digitalWrite(LED_BUILTIN, LOW);
  21. delay(1000);
  22. digitalWrite(LED_BUILTIN, HIGH);
  23. delay(1000);
  24. digitalWrite(LED_BUILTIN, LOW);
  25. // Try to keep your callbacks short (no delays ect)
  26. // otherwise it would slow down the loop() and have a bad impact
  27. // on real-time performance.
  28. }
  29.  
  30. void handleNoteOff(byte channel, byte pitch, byte velocity)
  31. {
  32. // Do something when the note is released.
  33. // Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
  34. }
  35.  
  36. // -----------------------------------------------------------------------------
  37.  
  38. void setup()
  39. {
  40.  
  41. pinMode(LED_BUILTIN, OUTPUT);
  42. digitalWrite(LED_BUILTIN, HIGH);
  43. delay(1000);
  44. digitalWrite(LED_BUILTIN, HIGH);
  45. delay(1000);
  46. digitalWrite(LED_BUILTIN, LOW);
  47.  
  48. // Connect the handleNoteOn function to the library,
  49. // so it is called upon reception of a NoteOn.
  50. MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function
  51.  
  52. // Do the same for NoteOffs
  53. MIDI.setHandleNoteOff(handleNoteOff);
  54.  
  55. // Initiate MIDI communications, listen to all channels
  56. MIDI.begin(MIDI_CHANNEL_OMNI);
  57. delay(100);
  58. Serial.println("started up");
  59. delay(1000);
  60. }
  61.  
  62. void loop()
  63. {
  64. // Call MIDI.read the fastest you can for real-time performance.
  65. MIDI.read();
  66. Serial.println(cnt);
  67. Serial.println("working");
  68. delay(200);
  69. // There is no need to check if there are messages incoming
  70. // if they are bound to a Callback function.
  71. // The attached method will be called automatically
  72. // when the corresponding message has been received.
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement