Revision 0:99a8a5ec3e56, committed 2017-08-10
- Comitter:
- mistery
- Date:
- Thu Aug 10 14:22:05 2017 +0000
- Commit message:
Changed in this revision
BLE_MIDI.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 99a8a5ec3e56 BLE_MIDI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BLE_MIDI.lib Thu Aug 10 14:22:05 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/mistery/code/BLE_MIDI/#7ffe438d3ed8
diff -r 000000000000 -r 99a8a5ec3e56 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 10 14:22:05 2017 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "BLEDevice.h" +#include "BLEMIDI.h" +#include "math.h" + +BLEDevice device; +BLEMIDI bleMidi(&device); + +PwmOut sound(P0_6); + +Ticker midinote; + +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); +} + +void note(){ + bleMidi.sendNoteOn(0, 63, 127); + } + +int main(void) { + device.onConnection(connectionCallback); + device.onDisconnection(disconnectionCallback); + + bleMidi.attachNoteOn(onNoteOn); + bleMidi.attachNoteOff(onNoteOff); + midinote.attach(¬e, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) + + for (;;) { + device.waitForEvent(); + + } +}