diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino b/libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino index 09ffabb2..14447f05 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino @@ -31,6 +31,9 @@ byte note_sequence[] = { 56,61,64,68,74,78,81,86,90,93,98,102 }; +// Variable to hold the last time we sent a note +unsigned long previousSend = 0; + void setup() { @@ -48,9 +51,6 @@ void setup() bledis.setModel("Bluefruit Feather52"); bledis.begin(); - // Set BLE write callback - blemidi.setWriteCallback(handleWrite); - // Initialize MIDI, and listen to all MIDI channels MIDI.begin(MIDI_CHANNEL_OMNI); @@ -92,11 +92,6 @@ void handleNoteOff(byte channel, byte pitch, byte velocity) Serial.println(); } -void handleWrite() { - // Tell the MIDI instance that we have new data. - MIDI.read(); -} - void loop() { @@ -110,6 +105,17 @@ void loop() return; } + // read any new MIDI messages + MIDI.read(); + + // Store the current time + unsigned long now = millis(); + + // Check if enough time has passed since last send + if (now - previousSend < 286) { + return; + } + // Setup variables for the current and previous // positions in the note sequence. int current = position; @@ -135,7 +141,7 @@ void loop() position = 0; } - // Wait before sending next note - delay(286); + // Log the send time + previousSend = now; }