Weiyu Liu / Mbed 2 deprecated DanceDanceRevolutionMbed2

Dependencies:   SDFileSystem mbed wave_player

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 File: DanceDanceFullGame_SECONDMBED.main.cpp
00003 Author: Akshay Nagendra, Weiyu Liu
00004 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
00005 */
00006 #include "mbed.h"
00007 #include "wave_player.h"
00008 #include "SDFileSystem.h"
00009 
00010 //setup variables and objects for music playing
00011 AnalogOut DACout(p18); //music played using analog out
00012 wave_player waver(&DACout);
00013 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sck, cs
00014 DigitalIn songSelected(p21); //signal from main mbed (asserted when a song has been selected)
00015 DigitalIn specificSong(p22); //signal from main mbed (asserted which specific song should be played)
00016 void playSound(char * wav);
00017 
00018 int main(){
00019     while(!songSelected){
00020              //wait until the main mbed send the ready signal for playing a song (players are still readying up and selecting music)   
00021     } 
00022     if(specificSong){   //a song has been selected and a '0' means Animals, and '1' means Novocaine
00023         wait(5); //a delay so that the arrow lines up with the first note of the song
00024         playSound("/sd/wavfiles/Novocaine2.wav");
00025     }
00026     else {
00027         wait(3.85); //a delay so that the arrow lines up with the first note of the song
00028         playSound("/sd/wavfiles/Animals2.wav"); 
00029     }  
00030 }
00031 
00032 void playSound(char * wav)
00033     //helper function to play the music 
00034 {
00035     // open wav file
00036     FILE *wave_file;
00037     wave_file=fopen(wav,"r");
00038 
00039     // play wav file
00040     waver.play(wave_file);
00041 
00042     // close wav file
00043     fclose(wave_file);
00044 }