An unfinished code

Dependencies:   4DGL-uLCD-SE PinDetect SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

main.cpp

Committer:
kbeck8
Date:
2016-12-21
Revision:
1:e293e396a208
Parent:
0:bdbd3d6fc5d5

File content as of revision 1:e293e396a208:

#include "mbed.h"
#include "wave_player.h"
#include "PinDetect.h"
#include "SDFileSystem.h"
#include <vector>
#include <string>


using namespace std;
int count = 0;
int rnjesus[] = {2,1,3,4,4,3,2,1,3,1,2,4,4,1,2,3,1,2,4,3,2,1,4,3,3,1,4,2,4,1,3,2,1,3,2,4,2,3,4,1,3,2,1,4,4,2,1,3,1,3,4,2,2,3,1,4,3,2,4,1,4,2,3,1,1,4,3,2,2,4,1,3,3,4,1,2,4,3,1,2,1,4,2,3,2,4,3,1,3,4,2,1,1,2,3,4};
bool buttonpressed = true;
string filenames[] = {"Ravenclaw","Hufflepuff","Slytherin","Gryffindor"};

SDFileSystem sd(p5,p6,p7,p8,"sd"); //set up SD reader
AnalogOut DACout(p18); //set up speaker
wave_player waver(&DACout); //set up wave player library         
                 
PinDetect Button(p13);

int main(){
    Button.mode(PullUp);   
    while(true){   
        if (count>=95){ // if the count is higher than the number of variables in rnjesus, resets count to 0
            count = 0;
        }
        buttonpressed = true;
        while (buttonpressed) {
                if (!Button){
                    buttonpressed = false;
                    wait_ms(100); //debounce button
            
                    string songname = filenames[rnjesus[count]-1];
                    string a = "/sd/Filenames/";
                    string b = ".wav";
                    string fname = a + songname + b; //retrieves the file name
                    
                    
                    char* name = new char[fname.length() + 1];
                    strcpy(name, fname.c_str()); 
                    wave_file=fopen(name,"r");
                    waver.play(wave_file);
                    fclose(wave_file);
                    
                    count = count + 1; // keep up the count
                }      
            }

        }
}