From 1c8f64264786b55b2a8a9fa95cc2ec45b96b849a Mon Sep 17 00:00:00 2001 From: fileneed Date: Wed, 2 Mar 2022 21:03:14 +0100 Subject: [PATCH] Added simple MIDI BLE test --- .../MidiBle-test1/MidiBle-test1.ino | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 ArduinoNano33BLE/MidiBle-test1/MidiBle-test1.ino diff --git a/ArduinoNano33BLE/MidiBle-test1/MidiBle-test1.ino b/ArduinoNano33BLE/MidiBle-test1/MidiBle-test1.ino new file mode 100644 index 0000000..335f2fd --- /dev/null +++ b/ArduinoNano33BLE/MidiBle-test1/MidiBle-test1.ino @@ -0,0 +1,68 @@ +#include + +//#include +//#include +//#include +#include + +BLEMIDI_CREATE_DEFAULT_INSTANCE() + +unsigned long t0 = millis(); +bool isConnected = false; + +// ----------------------------------------------------------------------------- +// When BLE connected, LED will turn on (indication that connection was successful) +// When receiving a NoteOn, LED will go out, on NoteOff, light comes back on. +// This is an easy and conveniant way to show that the connection is alive and working. +// ----------------------------------------------------------------------------- +void setup() +{ + Serial.begin(115200); + + Serial.println("MIDI-BLE TEST 1"); + Serial.println("2022-03-02"); + + MIDI.begin(); + + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + + BLEMIDI.setHandleConnected([]() { + isConnected = true; + digitalWrite(LED_BUILTIN, HIGH); + Serial.println("MIDI-BLE CONNECTED"); + + }); + + BLEMIDI.setHandleDisconnected([]() { + isConnected = false; + digitalWrite(LED_BUILTIN, LOW); + Serial.println("MIDI-BLE DISCONNECTED"); + + }); + + MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) { + digitalWrite(LED_BUILTIN, LOW); + }); + MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) { + digitalWrite(LED_BUILTIN, HIGH); + }); +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +void loop() +{ + MIDI.read(); + + if (isConnected && (millis() - t0) > 1000) + { + t0 = millis(); + + MIDI.sendNoteOn (60, 100, 1); // note 60, velocity 100 on channel 1 + Serial.println("ping"); + + + } +}