mbed2

Dependencies:   SDFileSystem mbed wave_player

Fork of drumsMusic by Can Kabuloglu

Committer:
ckabuloglu
Date:
Mon May 01 11:06:57 2017 +0000
Revision:
2:6488698b9d59
Parent:
1:cf186b6e4999
final push

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wliu88 0:4669e409389d 1 #include "mbed.h"
wliu88 0:4669e409389d 2 #include "wave_player.h"
wliu88 0:4669e409389d 3 #include "SDFileSystem.h"
wliu88 0:4669e409389d 4
ckabuloglu 2:6488698b9d59 5 // Define pins
ckabuloglu 2:6488698b9d59 6 SDFileSystem sd(p5, p6, p7, p8, "sd");
ckabuloglu 2:6488698b9d59 7 AnalogOut DACout(p18);
ckabuloglu 2:6488698b9d59 8 wave_player wave(&DACout);
ckabuloglu 2:6488698b9d59 9 DigitalIn gameStarted(p22);
ckabuloglu 1:cf186b6e4999 10
ckabuloglu 2:6488698b9d59 11 // Serial pc(USBTX, USBRX);
ckabuloglu 1:cf186b6e4999 12
ckabuloglu 1:cf186b6e4999 13 DigitalOut led1(LED1);
ckabuloglu 1:cf186b6e4999 14 DigitalOut led2(LED2);
ckabuloglu 1:cf186b6e4999 15
ckabuloglu 1:cf186b6e4999 16 float reading;
ckabuloglu 1:cf186b6e4999 17
wliu88 0:4669e409389d 18 void playSound(char * wav);
wliu88 0:4669e409389d 19
wliu88 0:4669e409389d 20 int main(){
ckabuloglu 2:6488698b9d59 21 // Wait for first mbed to pull down the pin
ckabuloglu 1:cf186b6e4999 22 wait(5.5);
ckabuloglu 2:6488698b9d59 23
ckabuloglu 2:6488698b9d59 24 // Wait until the player hits the start button
ckabuloglu 1:cf186b6e4999 25 while(!gameStarted){
ckabuloglu 2:6488698b9d59 26 led1 = 1;
wliu88 0:4669e409389d 27 }
ckabuloglu 2:6488698b9d59 28
ckabuloglu 2:6488698b9d59 29 // LED2 indicates the that mbed will start playing the music
ckabuloglu 1:cf186b6e4999 30 led1 = 0;
ckabuloglu 1:cf186b6e4999 31 led2 = 1;
ckabuloglu 2:6488698b9d59 32 wait(8.00); // Delay to line u first note with the song
ckabuloglu 2:6488698b9d59 33 playSound("/sd/obladi.wav");
wliu88 0:4669e409389d 34 }
wliu88 0:4669e409389d 35
ckabuloglu 2:6488698b9d59 36 // Function that plays the music
ckabuloglu 2:6488698b9d59 37 void playSound(char * wav) {
wliu88 0:4669e409389d 38 // open wav file
wliu88 0:4669e409389d 39 FILE *wave_file;
wliu88 0:4669e409389d 40 wave_file=fopen(wav,"r");
ckabuloglu 1:cf186b6e4999 41
wliu88 0:4669e409389d 42 // play wav file
ckabuloglu 2:6488698b9d59 43 wave.play(wave_file);
wliu88 0:4669e409389d 44
wliu88 0:4669e409389d 45 // close wav file
wliu88 0:4669e409389d 46 fclose(wave_file);
wliu88 0:4669e409389d 47 }