mbed working as a midi device through usb D-, D+

Dependencies:   USBDevice beep mbed

Files at this revision

API Documentation at this revision

Comitter:
ghostaudio
Date:
Tue Nov 19 03:23:23 2013 +0000
Commit message:
Improvement on the beep method i used before

Changed in this revision

USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
beep.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f24bc002bd2e USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Tue Nov 19 03:23:23 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#335f2506f422
diff -r 000000000000 -r f24bc002bd2e beep.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beep.lib	Tue Nov 19 03:23:23 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/dreschpe/code/beep/#d8e14429a95f
diff -r 000000000000 -r f24bc002bd2e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 19 03:23:23 2013 +0000
@@ -0,0 +1,50 @@
+// Edited from the Hello World example for the USBMIDI library
+// to play notes from the PwmOut using beep.....
+
+#include "mbed.h"
+#include "USBMIDI.h"
+#include "beep.h"
+
+//USBMIDI object
+USBMIDI midi;
+
+Beep buzzer(p22); // piezo one of two( this only needs one,
+Beep buzzer2(p21); // but piezo two made it more fun).....
+AnalogIn pot (p19); // and a potentiometer.....
+
+int freq = 0;
+
+// an array of frequencies from C2-C4 for freq.....
+int freqs[] = {261,277,293,311,329,349,369,391,415,440,466,493,523,
+                554,587,622,659,698,739,783,830,880,932,987,1046};
+
+//defining your midi notes as points in the array.....
+void show_message(MIDIMessage msg) {
+    if (msg.type() == MIDIMessage::NoteOnType) {
+        if (msg.velocity()!=0) {
+            freq = freqs[(msg.key()-48)];
+        }
+        else {
+            freq = 0;
+        }
+    }
+}
+
+int main() {
+    
+    // call back for midi messages received
+    midi.attach(show_message);
+    
+    while (1) {
+    
+    float time = (pot/2); // assign the pot to the time...
+    if (freq > 0){
+        buzzer.beep(freq,0.1); // between this beep...
+        wait (time);
+        buzzer2.beep((freq*2),0.1); // and this beep (1 octave up).
+        wait (time);
+        }
+    
+    wait (0.0001); // wait a millesecond and carry on...
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r f24bc002bd2e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 19 03:23:23 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file