mbed2
Dependencies: SDFileSystem mbed wave_player
Fork of DanceDanceRevolutionMbed2 by
main.cpp@0:4669e409389d, 2016-04-29 (annotated)
- Committer:
- wliu88
- Date:
- Fri Apr 29 02:07:01 2016 +0000
- Revision:
- 0:4669e409389d
- Child:
- 1:cf186b6e4999
new;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wliu88 | 0:4669e409389d | 1 | /* |
wliu88 | 0:4669e409389d | 2 | File: DanceDanceFullGame_SECONDMBED.main.cpp |
wliu88 | 0:4669e409389d | 3 | Author: Akshay Nagendra, Weiyu Liu |
wliu88 | 0:4669e409389d | 4 | 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 |
wliu88 | 0:4669e409389d | 5 | */ |
wliu88 | 0:4669e409389d | 6 | #include "mbed.h" |
wliu88 | 0:4669e409389d | 7 | #include "wave_player.h" |
wliu88 | 0:4669e409389d | 8 | #include "SDFileSystem.h" |
wliu88 | 0:4669e409389d | 9 | |
wliu88 | 0:4669e409389d | 10 | //setup variables and objects for music playing |
wliu88 | 0:4669e409389d | 11 | AnalogOut DACout(p18); //music played using analog out |
wliu88 | 0:4669e409389d | 12 | wave_player waver(&DACout); |
wliu88 | 0:4669e409389d | 13 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sck, cs |
wliu88 | 0:4669e409389d | 14 | DigitalIn songSelected(p21); //signal from main mbed (asserted when a song has been selected) |
wliu88 | 0:4669e409389d | 15 | DigitalIn specificSong(p22); //signal from main mbed (asserted which specific song should be played) |
wliu88 | 0:4669e409389d | 16 | void playSound(char * wav); |
wliu88 | 0:4669e409389d | 17 | |
wliu88 | 0:4669e409389d | 18 | int main(){ |
wliu88 | 0:4669e409389d | 19 | while(!songSelected){ |
wliu88 | 0:4669e409389d | 20 | //wait until the main mbed send the ready signal for playing a song (players are still readying up and selecting music) |
wliu88 | 0:4669e409389d | 21 | } |
wliu88 | 0:4669e409389d | 22 | if(specificSong){ //a song has been selected and a '0' means Animals, and '1' means Novocaine |
wliu88 | 0:4669e409389d | 23 | wait(5); //a delay so that the arrow lines up with the first note of the song |
wliu88 | 0:4669e409389d | 24 | playSound("/sd/wavfiles/Novocaine2.wav"); |
wliu88 | 0:4669e409389d | 25 | } |
wliu88 | 0:4669e409389d | 26 | else { |
wliu88 | 0:4669e409389d | 27 | wait(3.85); //a delay so that the arrow lines up with the first note of the song |
wliu88 | 0:4669e409389d | 28 | playSound("/sd/wavfiles/Animals2.wav"); |
wliu88 | 0:4669e409389d | 29 | } |
wliu88 | 0:4669e409389d | 30 | } |
wliu88 | 0:4669e409389d | 31 | |
wliu88 | 0:4669e409389d | 32 | void playSound(char * wav) |
wliu88 | 0:4669e409389d | 33 | //helper function to play the music |
wliu88 | 0:4669e409389d | 34 | { |
wliu88 | 0:4669e409389d | 35 | // open wav file |
wliu88 | 0:4669e409389d | 36 | FILE *wave_file; |
wliu88 | 0:4669e409389d | 37 | wave_file=fopen(wav,"r"); |
wliu88 | 0:4669e409389d | 38 | |
wliu88 | 0:4669e409389d | 39 | // play wav file |
wliu88 | 0:4669e409389d | 40 | waver.play(wave_file); |
wliu88 | 0:4669e409389d | 41 | |
wliu88 | 0:4669e409389d | 42 | // close wav file |
wliu88 | 0:4669e409389d | 43 | fclose(wave_file); |
wliu88 | 0:4669e409389d | 44 | } |