Dance Dance Revolution program for secondary mbed

Dependencies:   SDFileSystem mbed wave_player

Files at this revision

API Documentation at this revision

Comitter:
wliu88
Date:
Fri Apr 29 02:07:01 2016 +0000
Commit message:
new;

Changed in this revision

SDFileSystem.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
wave_player.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Fri Apr 29 02:07:01 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Apr 29 02:07:01 2016 +0000
@@ -0,0 +1,44 @@
+/*
+File: DanceDanceFullGame_SECONDMBED.main.cpp
+Author: Akshay Nagendra, Weiyu Liu
+Description: File responsible for operating the second mbed, in charge of listening to the main mbed for a ready signal and then playing the music for the game
+*/
+#include "mbed.h"
+#include "wave_player.h"
+#include "SDFileSystem.h"
+
+//setup variables and objects for music playing
+AnalogOut DACout(p18); //music played using analog out
+wave_player waver(&DACout);
+SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sck, cs
+DigitalIn songSelected(p21); //signal from main mbed (asserted when a song has been selected)
+DigitalIn specificSong(p22); //signal from main mbed (asserted which specific song should be played)
+void playSound(char * wav);
+
+int main(){
+    while(!songSelected){
+             //wait until the main mbed send the ready signal for playing a song (players are still readying up and selecting music)   
+    } 
+    if(specificSong){   //a song has been selected and a '0' means Animals, and '1' means Novocaine
+        wait(5); //a delay so that the arrow lines up with the first note of the song
+        playSound("/sd/wavfiles/Novocaine2.wav");
+    }
+    else {
+        wait(3.85); //a delay so that the arrow lines up with the first note of the song
+        playSound("/sd/wavfiles/Animals2.wav"); 
+    }  
+}
+
+void playSound(char * wav)
+    //helper function to play the music 
+{
+    // open wav file
+    FILE *wave_file;
+    wave_file=fopen(wav,"r");
+
+    // play wav file
+    waver.play(wave_file);
+
+    // close wav file
+    fclose(wave_file);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Apr 29 02:07:01 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/aae6fcc7d9bb
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wave_player.lib	Fri Apr 29 02:07:01 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sravet/code/wave_player/#acc3e18e77ad