Goran Mahovlic / Mbed 2 deprecated BLE_MIDI

Dependencies:   BLE_API mbed nRF51822_BLE_MIDI

Dependents:   BLE_MIDI_one_note_TEST

Fork of BLE_MIDI by Kaoru Shoji

Revision:
2:dbc6f81b9ba0
Parent:
1:cba2eba64f5c
diff -r cba2eba64f5c -r dbc6f81b9ba0 main.cpp
--- a/main.cpp	Fri Apr 03 04:24:01 2015 +0000
+++ b/main.cpp	Mon Apr 06 09:10:07 2015 +0000
@@ -1,12 +1,12 @@
 #include "mbed.h"
 #include "BLEDevice.h"
 #include "BLEMIDI.h"
+#include "math.h"
 
 BLEDevice device;
 BLEMIDI bleMidi(&device);
 
-DigitalOut led1(P0_0);
-InterruptIn button(P0_1);
+PwmOut sound(P0_0);
 
 void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) {
     bleMidi.onBleDisconnection(handle, reason);
@@ -17,17 +17,12 @@
 }
 
 void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) {
-    led1 = 1;
-    if (bleMidi.connected()) {
-        bleMidi.sendNoteOn(channel, note, 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) {
-    led1 = 0;
-    if (bleMidi.connected()) {
-        bleMidi.sendNoteOff(channel, note, velocity);
-    }
+    sound.pulsewidth(0);
 }
 
 int main(void) {