mbed2

Dependencies:   SDFileSystem mbed wave_player

Fork of DanceDanceRevolutionMbed2 by Weiyu Liu

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 gameStarted(p22); //signal from main mbed (asserted when a song has been selected)
00015 
00016 Serial pc(USBTX, USBRX);
00017 AnalogIn drum1(p15);
00018 
00019 DigitalOut led1(LED1);
00020 DigitalOut led2(LED2);
00021 
00022 float reading;
00023 
00024 void playSound(char * wav);
00025 
00026 int main(){
00027     wait(5.5);
00028     while(!gameStarted){
00029            led1 = 1;  
00030              //wait until the main mbed send the ready signal for playing a song (players are still readying up and selecting music)   
00031     } 
00032     led1 = 0;
00033     led2 = 1;
00034     wait(9.00); //a delay so that the arrow lines up with the first note of the song
00035     playSound("/sd/rock.wav");
00036 }
00037 
00038 void playSound(char * wav)
00039     //helper function to play the music 
00040 {
00041     // open wav file
00042     FILE *wave_file;
00043     wave_file=fopen(wav,"r");
00044  
00045     // play wav file
00046     waver.play(wave_file);
00047 
00048     // close wav file
00049     fclose(wave_file);
00050 }