mbed2
Dependencies: SDFileSystem mbed wave_player
Fork of drumsMusic by
main.cpp@1:cf186b6e4999, 2017-04-30 (annotated)
- Committer:
- ckabuloglu
- Date:
- Sun Apr 30 00:56:39 2017 +0000
- Revision:
- 1:cf186b6e4999
- Parent:
- 0:4669e409389d
- Child:
- 2:6488698b9d59
mbed2
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 |
ckabuloglu | 1:cf186b6e4999 | 14 | DigitalIn gameStarted(p22); //signal from main mbed (asserted when a song has been selected) |
ckabuloglu | 1:cf186b6e4999 | 15 | |
ckabuloglu | 1:cf186b6e4999 | 16 | Serial pc(USBTX, USBRX); |
ckabuloglu | 1:cf186b6e4999 | 17 | AnalogIn drum1(p15); |
ckabuloglu | 1:cf186b6e4999 | 18 | |
ckabuloglu | 1:cf186b6e4999 | 19 | DigitalOut led1(LED1); |
ckabuloglu | 1:cf186b6e4999 | 20 | DigitalOut led2(LED2); |
ckabuloglu | 1:cf186b6e4999 | 21 | |
ckabuloglu | 1:cf186b6e4999 | 22 | float reading; |
ckabuloglu | 1:cf186b6e4999 | 23 | |
wliu88 | 0:4669e409389d | 24 | void playSound(char * wav); |
wliu88 | 0:4669e409389d | 25 | |
wliu88 | 0:4669e409389d | 26 | int main(){ |
ckabuloglu | 1:cf186b6e4999 | 27 | wait(5.5); |
ckabuloglu | 1:cf186b6e4999 | 28 | while(!gameStarted){ |
ckabuloglu | 1:cf186b6e4999 | 29 | led1 = 1; |
wliu88 | 0:4669e409389d | 30 | //wait until the main mbed send the ready signal for playing a song (players are still readying up and selecting music) |
wliu88 | 0:4669e409389d | 31 | } |
ckabuloglu | 1:cf186b6e4999 | 32 | led1 = 0; |
ckabuloglu | 1:cf186b6e4999 | 33 | led2 = 1; |
ckabuloglu | 1:cf186b6e4999 | 34 | wait(9.00); //a delay so that the arrow lines up with the first note of the song |
ckabuloglu | 1:cf186b6e4999 | 35 | playSound("/sd/rock.wav"); |
wliu88 | 0:4669e409389d | 36 | } |
wliu88 | 0:4669e409389d | 37 | |
wliu88 | 0:4669e409389d | 38 | void playSound(char * wav) |
wliu88 | 0:4669e409389d | 39 | //helper function to play the music |
wliu88 | 0:4669e409389d | 40 | { |
wliu88 | 0:4669e409389d | 41 | // open wav file |
wliu88 | 0:4669e409389d | 42 | FILE *wave_file; |
wliu88 | 0:4669e409389d | 43 | wave_file=fopen(wav,"r"); |
ckabuloglu | 1:cf186b6e4999 | 44 | |
wliu88 | 0:4669e409389d | 45 | // play wav file |
wliu88 | 0:4669e409389d | 46 | waver.play(wave_file); |
wliu88 | 0:4669e409389d | 47 | |
wliu88 | 0:4669e409389d | 48 | // close wav file |
wliu88 | 0:4669e409389d | 49 | fclose(wave_file); |
wliu88 | 0:4669e409389d | 50 | } |