Skip to content

Commit 60dd5f1

Browse files
committed
add second read loop to MIDI rx test
1 parent 2534911 commit 60dd5f1

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tools/midi_tests/rx_arduino/rx_arduino.ino

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <bluefruit.h>
1515
#include <MIDI.h>
1616

17-
BLEMidi blemidi;
17+
BLEMidi blemidi = BLEMidi(256);
1818

1919
// Create a new instance of the Arduino MIDI Library,
2020
// and attach BluefruitLE MIDI as the transport.
@@ -46,9 +46,11 @@ void setup()
4646

4747
// Advertise device name in the Scan Response
4848
Bluefruit.ScanResponse.addName();
49-
49+
5050
// Start Advertising
5151
Bluefruit.Advertising.start();
52+
53+
Scheduler.startLoop(midiRead);
5254

5355
}
5456

@@ -57,6 +59,7 @@ void handleNoteOn(byte channel, byte pitch, byte velocity)
5759
on_count++;
5860
Serial.print("note on count: ");
5961
Serial.println(on_count, DEC);
62+
6063
}
6164

6265
void handleNoteOff(byte channel, byte pitch, byte velocity)
@@ -66,7 +69,21 @@ void handleNoteOff(byte channel, byte pitch, byte velocity)
6669
Serial.println(off_count, DEC);
6770
}
6871

69-
void loop()
72+
void loop() {
73+
}
74+
75+
void midiRead()
7076
{
77+
// Don't continue if we aren't connected.
78+
if (! Bluefruit.connected()) {
79+
return;
80+
}
81+
82+
// Don't continue if the connected device isn't ready to receive messages.
83+
if (! blemidi.notifyEnabled()) {
84+
return;
85+
}
86+
87+
// read any new MIDI messages
7188
MIDI.read();
7289
}

0 commit comments

Comments
 (0)