Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MIDI.h>
- MIDI_CREATE_DEFAULT_INSTANCE();
- //MIDI_CREATE_INSTANCE(HardwareSerial, Serial1,MIDI);
- int cnt=1;
- // -----------------------------------------------------------------------------
- // This function will be automatically called when a NoteOn is received.
- // It must be a void-returning function with the correct parameters,
- // see documentation here:
- // http://arduinomidilib.fortyseveneffects.com/a00022.html
- void handleNoteOn(byte channel, byte pitch, byte velocity)
- {
- // Do whatever you want when a note is pressed.
- cnt+=1;
- digitalWrite(LED_BUILTIN, LOW);
- delay(1000);
- digitalWrite(LED_BUILTIN, HIGH);
- delay(1000);
- digitalWrite(LED_BUILTIN, LOW);
- // Try to keep your callbacks short (no delays ect)
- // otherwise it would slow down the loop() and have a bad impact
- // on real-time performance.
- }
- void handleNoteOff(byte channel, byte pitch, byte velocity)
- {
- // Do something when the note is released.
- // Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
- }
- // -----------------------------------------------------------------------------
- void setup()
- {
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, HIGH);
- delay(1000);
- digitalWrite(LED_BUILTIN, HIGH);
- delay(1000);
- digitalWrite(LED_BUILTIN, LOW);
- // Connect the handleNoteOn function to the library,
- // so it is called upon reception of a NoteOn.
- MIDI.setHandleNoteOn(handleNoteOn); // Put only the name of the function
- // Do the same for NoteOffs
- MIDI.setHandleNoteOff(handleNoteOff);
- // Initiate MIDI communications, listen to all channels
- MIDI.begin(MIDI_CHANNEL_OMNI);
- delay(100);
- Serial.println("started up");
- delay(1000);
- }
- void loop()
- {
- // Call MIDI.read the fastest you can for real-time performance.
- MIDI.read();
- Serial.println(cnt);
- Serial.println("working");
- delay(200);
- // There is no need to check if there are messages incoming
- // if they are bound to a Callback function.
- // The attached method will be called automatically
- // when the corresponding message has been received.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement