From 2534911ae84729eb76c54dae4ab3abcc5ec1f188 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 16 Mar 2017 00:08:02 +0700 Subject: [PATCH] MIDI demo, remove autoMIDIread, use separate loop2() to call MIDI.read() --- .../examples/Peripheral/blemidi/blemidi.ino | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino b/libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino index cc5e619a..b87ca81c 100644 --- a/libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino +++ b/libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino @@ -32,7 +32,7 @@ byte note_sequence[] = { }; // Variable to hold the last time we sent a note -unsigned long previousSend = 0; +//unsigned long previousSend = 0; void setup() { @@ -54,7 +54,6 @@ void setup() // Initialize MIDI, and listen to all MIDI channels // This will also call blemidi service's begin() MIDI.begin(MIDI_CHANNEL_OMNI); - blemidi.autoMIDIread(&MIDI); // Attach the handleNoteOn function to the MIDI Library. It will // be called whenever the Bluefruit receives MIDI Note On messages. @@ -78,6 +77,7 @@ void setup() // Start Advertising Bluefruit.Advertising.start(); + Scheduler.startLoop(loop2); } void handleNoteOn(byte channel, byte pitch, byte velocity) @@ -96,7 +96,6 @@ void handleNoteOff(byte channel, byte pitch, byte velocity) void loop() { - // Don't continue if we aren't connected. if (! Bluefruit.connected()) { return; @@ -107,16 +106,13 @@ 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; - } +// 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. @@ -143,7 +139,25 @@ void loop() position = 0; } - // Log the send time - previousSend = now; + delay(286); + // Log the send time + //previousSend = now; } + +void loop2() +{ + // Don't continue if we aren't connected. + if (! Bluefruit.connected()) { + return; + } + + // Don't continue if the connected device isn't ready to receive messages. + if (! blemidi.notifyEnabled()) { + return; + } + + // read any new MIDI messages + MIDI.read(); +} +