diff --git a/res/Examples/MIDI_Basic_IO/MIDI_Basic_IO.ino b/res/Examples/MIDI_Basic_IO/MIDI_Basic_IO.ino new file mode 100644 index 0000000..161b67f --- /dev/null +++ b/res/Examples/MIDI_Basic_IO/MIDI_Basic_IO.ino @@ -0,0 +1,24 @@ +#include +/* + Basic I/O MIDI tutorial + by Franky + 28/07/2009 +*/ + +#define LED 13 // LED pin on Arduino board + +void setup() { + pinMode(LED, OUTPUT); + MIDI.begin(4); // Launch MIDI with default options + // input channel is set to 4 +} + +void loop() { + if (MIDI.read()) { + digitalWrite(LED,HIGH); // Blink the LED + MIDI.sendNoteOn(42,127,1); // Send a Note (pitch 42, velo 127 on channel 1) + delay(1000); // Wait for a second + MIDI.sendNoteOff(42,0,1); // Stop the note + digitalWrite(LED,LOW); + } +} diff --git a/res/Examples/MIDI_Bench/MIDI_Bench.ino b/res/Examples/MIDI_Bench/MIDI_Bench.ino new file mode 100644 index 0000000..301b395 --- /dev/null +++ b/res/Examples/MIDI_Bench/MIDI_Bench.ino @@ -0,0 +1,75 @@ +#include + +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; + + gCounter++; + + if (gCounter >= 100) { + + 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; + + MIDI.turnThruOff(); + + } + +} + + +void setup() +{ + + MIDI.begin(); + + Serial.begin(38400); + Serial.print("MCU Ready"); + + MIDI.sendNoteOn(69,127,1); + +} + + +void loop() +{ + + gTime_start = micros(); + + MIDI.read(); + +} + diff --git a/res/Examples/MIDI_Callbacks/MIDI_Callbacks.ino b/res/Examples/MIDI_Callbacks/MIDI_Callbacks.ino new file mode 100644 index 0000000..36d980e --- /dev/null +++ b/res/Examples/MIDI_Callbacks/MIDI_Callbacks.ino @@ -0,0 +1,36 @@ +#include + + +// 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.sourceforge.net/class_m_i_d_i___class.html + +void HandleNoteOn(byte channel, byte pitch, byte velocity) { + + // Do whatever you want when you receive a Note On. + + if (velocity == 0) { + // This acts like a NoteOff. + } + + // Try to keep your callbacks short (no delays ect) as the contrary would slow down the loop() + // and have a bad impact on real-time performance. +} + +void setup() { + // Initiate MIDI communications, listen to all channels + MIDI.begin(MIDI_CHANNEL_OMNI); + + // 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 + +} + + +void loop() { + // Call MIDI.read the fastest you can for real-time performance. + MIDI.read(); + + // There is no need to check if there are messages incoming if they are bound to a Callback function. +} diff --git a/res/Examples/MIDI_Input/MIDI_Input.ino b/res/Examples/MIDI_Input/MIDI_Input.ino new file mode 100644 index 0000000..5ecb07d --- /dev/null +++ b/res/Examples/MIDI_Input/MIDI_Input.ino @@ -0,0 +1,43 @@ +#include +/* + MIDI Input tutorial + by Franky + 28/07/2009 + + NOTE: for easier MIDI input reading, + take a look a the Callbacks example. + +*/ + +#define LED 13 // LED pin on Arduino board + +void BlinkLed(byte num) { // Basic blink function + for (byte i=0;i