Edited from the Hello World example for the USBMIDI library to play notes from a PwmOut using beep.....

Dependencies:   USBDevice beep mbed

Files at this revision

API Documentation at this revision

Comitter:
ghostaudio
Date:
Mon Oct 14 03:22:06 2013 +0000
Parent:
0:e2158c97fd68
Commit message:
Edited from the Hello World example for the USBMIDI library to play notes from the PwmOut using beep..... now fixed ;)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e2158c97fd68 -r 910d83dfc8b7 main.cpp
--- a/main.cpp	Sun Oct 13 23:56:23 2013 +0000
+++ b/main.cpp	Mon Oct 14 03:22:06 2013 +0000
@@ -1,4 +1,5 @@
-// Hello World example for the USBMIDI library.... edited to play notes from the PwmOut using beep
+// Edited from the Hello World example for the USBMIDI library
+// to play notes from the PwmOut using beep.....
 
 #include "mbed.h"
 #include "USBMIDI.h"
@@ -10,55 +11,112 @@
 
 Beep buzzer(p26);
 
+int freq = 0;
+
+
+//defining your midi notes as frequencies...
 void show_message(MIDIMessage msg) {
     switch (msg.type()) {
         case MIDIMessage::NoteOnType:
             switch (msg.key()) {
                 case 48:
-                    buzzer.beep((1/130),2);
+                    freq = 261;
                     break;
                 case 49:
-                    buzzer.beep((1/138),2);
+                    freq = 277;
                     break;
                 case 50:
-                    buzzer.beep((1/146),2);
+                    freq = 293;
                     break;
                 case 51:
-                    buzzer.beep((1/155),2);
+                    freq = 311;
                     break;
                 case 52:
-                    buzzer.beep((1/164),2);
+                    freq = 329;
                     break;
                 case 53:
-                    buzzer.beep((1/174),2);
+                    freq = 349;
                     break;
                 case 54:
-                    buzzer.beep((1/184),2);
+                    freq = 369;
                     break;
                 case 55:
-                    buzzer.beep((1/195),2);
+                    freq = 391;
                     break;
                 case 56:
-                    buzzer.beep((1/207),2);
+                    freq = 415;
                     break;
                 case 57:
-                    buzzer.beep((1/220),2);
+                    freq = 440;
                     break;
                 case 58:
-                    buzzer.beep((1/233),2);
+                    freq = 466;
                     break;
                 case 59:
-                    buzzer.beep((1/246),2);
+                    freq = 493;
                     break;
                 case 60:
-                    buzzer.beep((1/261),2);
+                    freq = 523;
+                    break;
+                case 61:
+                    freq = 554;
+                    break;
+                case 62:
+                    freq = 587;
+                    break;
+                case 63:
+                    freq = 622;
+                    break;
+                case 64:
+                    freq = 659;
+                    break;
+                case 65:
+                    freq = 698;
+                    break;
+                case 66:
+                    freq = 739;
                     break;
+                case 67:
+                    freq = 783;
+                    break;
+                case 68:
+                    freq = 830;
+                    break;
+                case 69:
+                    freq = 880;
+                    break;
+                case 70:
+                    freq = 932;
+                    break;
+                case 71:
+                    freq = 987;
+                    break;
+                case 72:
+                    freq = 1046;
+                    break;
+            }
+            switch (msg.velocity()) {
+                case 0:
+                 freq = 0;
             }
             break;
-        case MIDIMessage::NoteOffType:
-        default:
-            buzzer.beep(1.0,0.1);
+        }
+}
+
+float note = 60; 
+
+int main() {
+    
+    // call back for messages received
+    midi.attach(show_message);
     
-
+    while (1) {
+    
+    float note = freq;    
+    if (note > 0){
+        buzzer.beep(note,0.1);
         }
+    
+    wait ((0.01));
+    }
 }
\ No newline at end of file