Simple audio out using mbed templates

Dependencies:   mbed

Revision:
0:05e1cec99ce1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Music_main.cpp	Tue Jun 10 12:14:05 2014 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+
+#define C3 131
+#define D3 147
+#define E3 165
+#define F3 175
+#define G3 196
+#define A3 220
+#define B3 247
+#define C4 262
+#define D4 294
+#define E4 330
+#define F4 349
+#define G4 392
+#define A4 440
+#define B4 494
+#define C5 523
+#define A5 880
+#define B5 988
+#define Pause 1
+
+Ticker tick;
+DigitalOut led1(LED_RED);
+DigitalOut led2(LED_GREEN);
+DigitalOut gpo(D10);
+
+void flip() {
+    led2 = !led2;
+    gpo = !gpo;
+}
+
+int main() {
+    int Notes_Hz[] = {Pause, G4, F4, G4, Pause, D3, B5, A4, Pause, G4, E3, E4, E4, E4, F4, G4,Pause,
+                      G4, F4, G4, Pause, D3, B5, A4, Pause, G4, E3, E4, E4, E4, F4, G4, Pause};
+    int i;
+    int bpm = 120;
+    //tick.attach(&flip, 0.7); // setup ticker to call flip led2 after 0.7 seconds
+
+    while (1) {
+        i = 0;
+        while (Notes_Hz[i]) {
+            led1 = !led1;
+            tick.attach(&flip, 0.5/Notes_Hz[i]);
+            wait (50.0/bpm); // bpm = beats per minute
+            tick.attach(&flip, 1);
+            wait (10.0/bpm); // 
+            i++;
+        }
+    }
+}
\ No newline at end of file