Datasheet
int position = 0;
// Store example melody as an array of note values
byte note_sequence[] = {
74,78,81,86,90,93,98,102,57,61,66,69,73,78,81,85,88,92,97,100,97,92,88,85,81,78,
74,69,66,62,57,62,66,69,74,78,81,86,90,93,97,102,97,93,90,85,81,78,73,68,64,61,
56,61,64,68,74,78,81,86,90,93,98,102
};
void setup()
{
Serial.begin(115200);
Serial.println("Adafruit Bluefruit52 MIDI over Bluetooth LE Example");
Bluefruit.begin();
Bluefruit.setName("Bluefruit52 MIDI");
// Setup the on board blue LED to be enabled on CONNECT
Bluefruit.autoConnLed(true);
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather52");
bledis.begin();
// Initialize MIDI, and listen to all MIDI channels
// This will also call blemidi service's begin()
MIDI.begin(MIDI_CHANNEL_OMNI);
// Attach the handleNoteOn function to the MIDI Library. It will
// be called whenever the Bluefruit receives MIDI Note On messages.
MIDI.setHandleNoteOn(handleNoteOn);
// Do the same for MIDI Note Off messages.
MIDI.setHandleNoteOff(handleNoteOff);
// Set General Discoverable Mode flag
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
// Advertise TX Power
Bluefruit.Advertising.addTxPower();
// Advertise BLE MIDI Service
Bluefruit.Advertising.addService(blemidi);
// Advertise device name in the Scan Response
Bluefruit.ScanResponse.addName();
// Start Advertising
Bluefruit.Advertising.start();
// Start MIDI read loop
Scheduler.startLoop(midiRead);
}
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
// Log when a note is pressed.
Serial.printf("Note on: channel = %d, pitch = %d, velocity - %d", channel, pitch, velocity);
Serial.println();
}
© Adafruit Industries https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide Page 139 of 175