mbed2

Dependencies:   SDFileSystem mbed wave_player

Fork of drumsMusic by Can Kabuloglu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "wave_player.h"
00003 #include "SDFileSystem.h"
00004 
00005 // Define pins
00006 SDFileSystem sd(p5, p6, p7, p8, "sd"); 
00007 AnalogOut DACout(p18); 
00008 wave_player wave(&DACout);
00009 DigitalIn gameStarted(p22);
00010 
00011 // Serial pc(USBTX, USBRX);
00012 
00013 DigitalOut led1(LED1);
00014 DigitalOut led2(LED2);
00015 
00016 float reading;
00017 
00018 void playSound(char * wav);
00019 
00020 int main(){
00021     // Wait for first mbed to pull down the pin
00022     wait(5.5);
00023     
00024     // Wait until the player hits the start button
00025     while(!gameStarted){
00026         led1 = 1;  
00027     } 
00028     
00029     // LED2 indicates the that mbed will start playing the music
00030     led1 = 0;
00031     led2 = 1;
00032     wait(8.00); // Delay to line u first note with the song
00033     playSound("/sd/obladi.wav");
00034 }
00035 
00036 // Function that plays the music
00037 void playSound(char * wav) {
00038     // open wav file
00039     FILE *wave_file;
00040     wave_file=fopen(wav,"r");
00041  
00042     // play wav file
00043     wave.play(wave_file);
00044 
00045     // close wav file
00046     fclose(wave_file);
00047 }