Plays the Tetris theme on a buzzer

Dependencies:   beepLib mbed

Fork of popcorn by David Styles

Files at this revision

API Documentation at this revision

Comitter:
wsjoukes
Date:
Fri Nov 09 16:34:20 2012 +0000
Parent:
0:a0cac22ff2e7
Commit message:
Commit message

Changed in this revision

beep.lib Show diff for this revision Revisions of this file
beepLib.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show diff for this revision Revisions of this file
tetris.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r a0cac22ff2e7 -r 5d7ecf6a9525 beep.lib
--- a/beep.lib	Fri May 20 15:59:17 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/dreschpe/code/beep/#5a8242af60ba
diff -r a0cac22ff2e7 -r 5d7ecf6a9525 beepLib.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/beepLib.lib	Fri Nov 09 16:34:20 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/wsjoukes/code/beepLib/#e4cbc1efcbe4
diff -r a0cac22ff2e7 -r 5d7ecf6a9525 main.cpp
--- a/main.cpp	Fri May 20 15:59:17 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-#include "mbed.h"
-#include "beep.h"
-Beep buzzer(p23);
-
-DigitalOut myled(LED1);
-
-void play(char* note);
-
-void popcorn() {
-
-    play("e");
-    play("d");
-    play("e");
-    play("c");
-    play("gb");
-    play("c");
-    play("eb");
-    play("w");
-    play("e");
-    play("d");
-    play("e");
-    play("c");
-    play("gb");
-    play("c");
-    play("eb");
-    play("w");
-
-    play("e");
-    play("f#");
-    play("g");
-    play("f#");
-    play("g");
-    play("e");
-    play("f#");
-    play("e");
-    play("f#");
-    play("d");
-    play("e");
-    play("d");
-    play("e");
-    play("d");
-    play("e");
-
-    play("w");
-
-    play("e");
-    play("d");
-    play("e");
-    play("c");
-    play("gb");
-    play("c");
-    play("eb");
-    play("w");
-    play("e");
-    play("d");
-    play("e");
-    play("c");
-    play("gb");
-    play("c");
-    play("eb");
-    play("w");
-
-    play("e");
-    play("f#");
-    play("g");
-    play("f#");
-    play("g");
-    play("e");
-    play("f#");
-    play("e");
-    play("f#");
-    play("d");
-    play("e");
-    play("d");
-    play("e");
-    play("d");
-    play("g");
-
-}
-
-
-void play(char* note) {
-    if (note=="a") {
-        buzzer.beep(880,0.1);
-    }
-    if (note=="b") {
-        buzzer.beep(987,0.1);
-    }
-    if (note=="c") {
-        buzzer.beep(1024,0.1);
-    }
-    if (note=="d") {
-        buzzer.beep(1175,0.1);
-    }
-    if (note=="e") {
-        buzzer.beep(1319,0.1);
-    }
-    if (note=="f") {
-        buzzer.beep(1397,0.1);
-    }
-    if (note=="g") {
-        buzzer.beep(1568,0.1);
-    }
-
-    if (note=="gb") {
-        buzzer.beep(830,0.1);
-    }
-    if (note=="eb") {
-        buzzer.beep(659,0.1);
-    }
-    if (note=="f#") {
-        buzzer.beep(1480,0.1);
-    }
-    if (note=="w") {
-        wait(0.05);
-    }
-    wait (0.2); //wait while the note plays.
-}
-
-
-int main() {
-    popcorn();
-}
diff -r a0cac22ff2e7 -r 5d7ecf6a9525 tetris.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tetris.cpp	Fri Nov 09 16:34:20 2012 +0000
@@ -0,0 +1,114 @@
+#include "mbed.h"
+#include "beep.h"
+Beep buzzer(p23);
+
+DigitalOut myled(LED1);
+
+void play(char* note, char* length);
+
+void tetris() {
+
+   
+    play("g", "Q");
+    play("d", "E");
+    play("eb", "E");
+    play("f", "Q");
+    play("eb", "E");
+    play("d", "E");
+    play("c", "Q");
+    play("c", "E");
+    play("eb", "E");
+    play("g", "Q");
+    play("f", "E");
+    play("eb", "E");
+    play("d", "T");
+    play("eb", "E");
+    play("f", "Q");
+    play("g", "Q");
+    play("eb", "S");
+    play("c", "S");
+    play("c", "S");
+    play("r", "Q");
+    play("r", "E");
+    play("f", "T");
+    play("abh", "E");
+    play("ch", "Q");
+    play("bbh", "E");
+    play("abh", "E");
+    play("g", "T");
+    play("eb", "E");
+    play("g", "Q");
+    play("f", "E");
+    play("eb", "E");
+    play("d", "Q");
+    play("d", "E");
+    play("eb", "E");
+    play("f", "Q");
+    play("g", "Q");
+    play("eb", "Q");
+    play("c", "S");
+    play("c", "S");
+    play("r", "Q");
+
+}
+
+
+void play(char* note, char* length) {
+    
+    if (note=="ab") {
+        buzzer.beepFreq(830);
+    }
+    if (note=="abh"){
+    buzzer.beepFreq(1661);
+    }
+    if (note=="bb") {
+        buzzer.beepFreq(932);
+    }
+    if (note=="bbh") {
+        buzzer.beepFreq(1865);
+    }
+    if (note=="c") {
+        buzzer.beepFreq(1046);
+    }
+    if (note=="ch") {
+        buzzer.beepFreq(2093);
+    }
+    if (note=="d") {
+        buzzer.beepFreq(1175);
+    }
+    if (note=="eb") {
+        buzzer.beepFreq(1245);
+    }
+    if (note=="f") {
+        buzzer.beepFreq(1397);
+    }
+    if (note=="g") {
+        buzzer.beepFreq(1568);
+    }
+    if (note=="r") {
+        buzzer.beepFreq(0);
+    }
+    
+    if (length=="Q"){ //quarter note
+        buzzer.beepTime(0.5);
+        wait (0.5);
+    }
+    if (length=="E"){ // eighth note
+        buzzer.beepTime(0.25);
+        wait(0.25);
+    }
+    if (length=="T"){ //quarter+eigthh note
+        buzzer.beepTime(0.75);
+        wait(0.75);
+    }
+    if (length=="S"){ //staccato note
+    buzzer.beepTime(0.25);
+    wait(0.5);
+    }
+
+}
+
+
+int main() {
+    tetris();
+}