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@2:dbc6f81b9ba0, 2015-04-06 (annotated)
- Committer:
- kshoji
- Date:
- Mon Apr 06 09:10:07 2015 +0000
- Revision:
- 2:dbc6f81b9ba0
- Parent:
- 1:cba2eba64f5c
Add documents
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| kshoji | 0:83889dc90473 | 1 | #include "mbed.h" |
| kshoji | 0:83889dc90473 | 2 | #include "BLEDevice.h" |
| kshoji | 0:83889dc90473 | 3 | #include "BLEMIDI.h" |
| kshoji | 2:dbc6f81b9ba0 | 4 | #include "math.h" |
| kshoji | 0:83889dc90473 | 5 | |
| kshoji | 0:83889dc90473 | 6 | BLEDevice device; |
| kshoji | 0:83889dc90473 | 7 | BLEMIDI bleMidi(&device); |
| kshoji | 0:83889dc90473 | 8 | |
| kshoji | 2:dbc6f81b9ba0 | 9 | PwmOut sound(P0_0); |
| kshoji | 0:83889dc90473 | 10 | |
| kshoji | 0:83889dc90473 | 11 | void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { |
| kshoji | 0:83889dc90473 | 12 | bleMidi.onBleDisconnection(handle, reason); |
| kshoji | 0:83889dc90473 | 13 | } |
| kshoji | 0:83889dc90473 | 14 | |
| kshoji | 0:83889dc90473 | 15 | void connectionCallback(Gap::Handle_t handle, Gap::addr_type_t type, const Gap::address_t addr, const Gap::ConnectionParams_t *params) { |
| kshoji | 0:83889dc90473 | 16 | bleMidi.onBleConnection(handle, type, addr, params); |
| kshoji | 0:83889dc90473 | 17 | } |
| kshoji | 0:83889dc90473 | 18 | |
| kshoji | 0:83889dc90473 | 19 | void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) { |
| kshoji | 2:dbc6f81b9ba0 | 20 | sound.write(0.5f); |
| kshoji | 2:dbc6f81b9ba0 | 21 | sound.period(1.0f / (440.0f * (float)pow(2.0, (note - 69.0) / 12.0))); |
| kshoji | 0:83889dc90473 | 22 | } |
| kshoji | 0:83889dc90473 | 23 | |
| kshoji | 0:83889dc90473 | 24 | void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity) { |
| kshoji | 2:dbc6f81b9ba0 | 25 | sound.pulsewidth(0); |
| kshoji | 0:83889dc90473 | 26 | } |
| kshoji | 0:83889dc90473 | 27 | |
| kshoji | 0:83889dc90473 | 28 | int main(void) { |
| kshoji | 0:83889dc90473 | 29 | device.onConnection(connectionCallback); |
| kshoji | 0:83889dc90473 | 30 | device.onDisconnection(disconnectionCallback); |
| kshoji | 0:83889dc90473 | 31 | |
| kshoji | 0:83889dc90473 | 32 | bleMidi.attachNoteOn(onNoteOn); |
| kshoji | 0:83889dc90473 | 33 | bleMidi.attachNoteOff(onNoteOff); |
| kshoji | 0:83889dc90473 | 34 | |
| kshoji | 0:83889dc90473 | 35 | for (;;) { |
| kshoji | 0:83889dc90473 | 36 | device.waitForEvent(); |
| kshoji | 0:83889dc90473 | 37 | } |
| kshoji | 0:83889dc90473 | 38 | } |
