An unfinished code

Dependencies:   4DGL-uLCD-SE PinDetect SDFileSystem mbed

Fork of SDFileSystem_HelloWorld by mbed official

Revision:
1:e293e396a208
Parent:
0:bdbd3d6fc5d5
--- a/main.cpp	Fri Dec 07 11:25:01 2012 +0000
+++ b/main.cpp	Wed Dec 21 17:20:33 2016 +0000
@@ -1,19 +1,54 @@
 #include "mbed.h"
+#include "wave_player.h"
+#include "PinDetect.h"
 #include "SDFileSystem.h"
- 
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
- 
-int main() {
-    printf("Hello World!\n");   
- 
-    mkdir("/sd/mydir", 0777);
-    
-    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
-    fprintf(fp, "Hello fun SD Card World!");
-    fclose(fp); 
- 
-    printf("Goodbye World!\n");
-}
+#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
+                }      
+            }
+
+        }
+}                
+
+
+
+