An unfinished code

Dependencies:   4DGL-uLCD-SE PinDetect SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Committer:
kbeck8
Date:
Wed Dec 21 17:20:33 2016 +0000
Revision:
1:e293e396a208
Parent:
0:bdbd3d6fc5d5
An almost functional sorting hat.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
kbeck8 1:e293e396a208 2 #include "wave_player.h"
kbeck8 1:e293e396a208 3 #include "PinDetect.h"
mbed_official 0:bdbd3d6fc5d5 4 #include "SDFileSystem.h"
kbeck8 1:e293e396a208 5 #include <vector>
kbeck8 1:e293e396a208 6 #include <string>
kbeck8 1:e293e396a208 7
kbeck8 1:e293e396a208 8
kbeck8 1:e293e396a208 9 using namespace std;
kbeck8 1:e293e396a208 10 int count = 0;
kbeck8 1:e293e396a208 11 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};
kbeck8 1:e293e396a208 12 bool buttonpressed = true;
kbeck8 1:e293e396a208 13 string filenames[] = {"Ravenclaw","Hufflepuff","Slytherin","Gryffindor"};
kbeck8 1:e293e396a208 14
kbeck8 1:e293e396a208 15 SDFileSystem sd(p5,p6,p7,p8,"sd"); //set up SD reader
kbeck8 1:e293e396a208 16 AnalogOut DACout(p18); //set up speaker
kbeck8 1:e293e396a208 17 wave_player waver(&DACout); //set up wave player library
kbeck8 1:e293e396a208 18
kbeck8 1:e293e396a208 19 PinDetect Button(p13);
kbeck8 1:e293e396a208 20
kbeck8 1:e293e396a208 21 int main(){
kbeck8 1:e293e396a208 22 Button.mode(PullUp);
kbeck8 1:e293e396a208 23 while(true){
kbeck8 1:e293e396a208 24 if (count>=95){ // if the count is higher than the number of variables in rnjesus, resets count to 0
kbeck8 1:e293e396a208 25 count = 0;
kbeck8 1:e293e396a208 26 }
kbeck8 1:e293e396a208 27 buttonpressed = true;
kbeck8 1:e293e396a208 28 while (buttonpressed) {
kbeck8 1:e293e396a208 29 if (!Button){
kbeck8 1:e293e396a208 30 buttonpressed = false;
kbeck8 1:e293e396a208 31 wait_ms(100); //debounce button
kbeck8 1:e293e396a208 32
kbeck8 1:e293e396a208 33 string songname = filenames[rnjesus[count]-1];
kbeck8 1:e293e396a208 34 string a = "/sd/Filenames/";
kbeck8 1:e293e396a208 35 string b = ".wav";
kbeck8 1:e293e396a208 36 string fname = a + songname + b; //retrieves the file name
kbeck8 1:e293e396a208 37
kbeck8 1:e293e396a208 38
kbeck8 1:e293e396a208 39 char* name = new char[fname.length() + 1];
kbeck8 1:e293e396a208 40 strcpy(name, fname.c_str());
kbeck8 1:e293e396a208 41 wave_file=fopen(name,"r");
kbeck8 1:e293e396a208 42 waver.play(wave_file);
kbeck8 1:e293e396a208 43 fclose(wave_file);
kbeck8 1:e293e396a208 44
kbeck8 1:e293e396a208 45 count = count + 1; // keep up the count
kbeck8 1:e293e396a208 46 }
kbeck8 1:e293e396a208 47 }
kbeck8 1:e293e396a208 48
kbeck8 1:e293e396a208 49 }
kbeck8 1:e293e396a208 50 }
kbeck8 1:e293e396a208 51
kbeck8 1:e293e396a208 52
kbeck8 1:e293e396a208 53
kbeck8 1:e293e396a208 54