Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822_BLE_MIDI
Dependents: BLE_MIDI_one_note_TEST
Fork of BLE_MIDI by
main.cpp
- Committer:
- kshoji
- Date:
- 2015-04-06
- Revision:
- 2:dbc6f81b9ba0
- Parent:
- 1:cba2eba64f5c
File content as of revision 2:dbc6f81b9ba0:
#include "mbed.h"
#include "BLEDevice.h"
#include "BLEMIDI.h"
#include "math.h"
BLEDevice device;
BLEMIDI bleMidi(&device);
PwmOut sound(P0_0);
void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) {
bleMidi.onBleDisconnection(handle, reason);
}
void connectionCallback(Gap::Handle_t handle, Gap::addr_type_t type, const Gap::address_t addr, const Gap::ConnectionParams_t *params) {
bleMidi.onBleConnection(handle, type, addr, params);
}
void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) {
sound.write(0.5f);
sound.period(1.0f / (440.0f * (float)pow(2.0, (note - 69.0) / 12.0)));
}
void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity) {
sound.pulsewidth(0);
}
int main(void) {
device.onConnection(connectionCallback);
device.onDisconnection(disconnectionCallback);
bleMidi.attachNoteOn(onNoteOn);
bleMidi.attachNoteOff(onNoteOff);
for (;;) {
device.waitForEvent();
}
}
