Skip to content

Commit 2534911

Browse files
committed
MIDI demo, remove autoMIDIread, use separate loop2() to call MIDI.read()
1 parent 812fbad commit 2534911

File tree

1 file changed

+27
-13
lines changed
  • libraries/Bluefruit52Lib/examples/Peripheral/blemidi

1 file changed

+27
-13
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/blemidi/blemidi.ino

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ byte note_sequence[] = {
3232
};
3333

3434
// Variable to hold the last time we sent a note
35-
unsigned long previousSend = 0;
35+
//unsigned long previousSend = 0;
3636

3737
void setup()
3838
{
@@ -54,7 +54,6 @@ void setup()
5454
// Initialize MIDI, and listen to all MIDI channels
5555
// This will also call blemidi service's begin()
5656
MIDI.begin(MIDI_CHANNEL_OMNI);
57-
blemidi.autoMIDIread(&MIDI);
5857

5958
// Attach the handleNoteOn function to the MIDI Library. It will
6059
// be called whenever the Bluefruit receives MIDI Note On messages.
@@ -78,6 +77,7 @@ void setup()
7877
// Start Advertising
7978
Bluefruit.Advertising.start();
8079

80+
Scheduler.startLoop(loop2);
8181
}
8282

8383
void handleNoteOn(byte channel, byte pitch, byte velocity)
@@ -96,7 +96,6 @@ void handleNoteOff(byte channel, byte pitch, byte velocity)
9696

9797
void loop()
9898
{
99-
10099
// Don't continue if we aren't connected.
101100
if (! Bluefruit.connected()) {
102101
return;
@@ -107,16 +106,13 @@ void loop()
107106
return;
108107
}
109108

110-
// read any new MIDI messages
111-
//MIDI.read();
112-
113109
// Store the current time
114-
unsigned long now = millis();
115-
116-
// Check if enough time has passed since last send
117-
if (now - previousSend < 286) {
118-
return;
119-
}
110+
// unsigned long now = millis();
111+
//
112+
// // Check if enough time has passed since last send
113+
// if (now - previousSend < 286) {
114+
// return;
115+
// }
120116

121117
// Setup variables for the current and previous
122118
// positions in the note sequence.
@@ -143,7 +139,25 @@ void loop()
143139
position = 0;
144140
}
145141

142+
delay(286);
143+
146144
// Log the send time
147-
previousSend = now;
145+
//previousSend = now;
146+
}
148147

148+
void loop2()
149+
{
150+
// Don't continue if we aren't connected.
151+
if (! Bluefruit.connected()) {
152+
return;
153+
}
154+
155+
// Don't continue if the connected device isn't ready to receive messages.
156+
if (! blemidi.notifyEnabled()) {
157+
return;
158+
}
159+
160+
// read any new MIDI messages
161+
MIDI.read();
149162
}
163+

0 commit comments

Comments
 (0)