Faizan and Pages fun little game

Dependencies:   4DGL-uLCD-SE mbed SDFileSystem wave_player

Revision:
16:702313ea97b9
Parent:
15:b18537055368
Child:
17:95948ed73911
--- a/main.cpp	Mon Oct 31 18:48:11 2016 +0000
+++ b/main.cpp	Mon Oct 31 19:07:47 2016 +0000
@@ -1,6 +1,8 @@
 #include "mbed.h"
 #include "uLCD_4DGL.h"
-#include "SongPlayer.h"
+//#include "SongPlayer.h"
+#include "SDFileSystem.h"
+#include "wave_player.h"
 #include "NavSwitch.h"
 #include "food.h"
 #include "stack.h"
@@ -24,8 +26,10 @@
 #define BROWN 0xf4a460
 
 uLCD_4DGL lcd(p9,p10,p11);
-SongPlayer speaker(p26);
-Nav_Switch joystick(p20, p19, p18, p17, p16); // pin order on Sparkfun breakout
+SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+AnalogOut DACout(p18);
+wave_player waver(&DACout);
+Nav_Switch joystick(p20, p19, p17, p16, p15); // pin order on Sparkfun breakout
 DigitalIn speed(p21);
 DigitalIn pause(p22);
 
@@ -55,7 +59,13 @@
     lcd.filled_rectangle(34, 74, 44, 78, RED); // tomato
     lcd.filled_rectangle(30, 94, 50, 96, BROWN); // bottom bun
     lcd.filled_rectangle(34, 98, 44, 97, BROWN); 
-    wait(2);
+    
+    FILE *wave_file;
+    lcd.printf("\n\n\nHello, wave world!\n"); // for debug right now
+    wave_file=fopen("/sd/start.wav","r");
+    waver.play(wave_file);
+    fclose(wave_file);
+    
     lcd.text_string("bun", 11, 3, FONT_7X8, WHITE);
     wait(1);
     lcd.text_string("cheese", 11, 5, FONT_7X8, WHITE);
@@ -165,11 +175,17 @@
 
 void updateScore(int sandwichSize) {
     char scoreString[2];   // max 2-digit score
-    // C#, D#, F, A, D, E, F#, A#, _, A, Bb, B, C
-    float notes[14] = {554.4, 622.3, 698.5, 880, 587.3, 659.3, 740, 932.3, 0, 440, 466.2, 493.9, 523.3, 0};
-    float times[14] = {0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.48, 0.48, 0.48, 0.48, 0.48, 0};
+//    // C#, D#, F, A, D, E, F#, A#, _, A, Bb, B, C
+//    float notes[14] = {554.4, 622.3, 698.5, 880, 587.3, 659.3, 740, 932.3, 0, 440, 466.2, 493.9, 523.3, 0};
+//    float times[14] = {0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.24, 0.48, 0.48, 0.48, 0.48, 0.48, 0};
+//    speaker.PlaySong(notes, times);
 
-    speaker.PlaySong(notes, times);
+    FILE *wave_file;
+    lcd.printf("\n\n\nHello, wave world!\n"); // for debug right now
+    wave_file=fopen("/sd/score.wav","r");
+    waver.play(wave_file);
+    fclose(wave_file);
+
     score += sandwichSize;
     score = (score > 99) ? score - 100 : score; // score rollover
     sprintf(scoreString, "%d", score); // keep score as a char string
@@ -178,10 +194,17 @@
 
 void drawLives() {
     // G, D, _, D, D, C, B, G, E, _, E, C, _
-    float notes[13] = {195.9, 293.6, 0, 293.6, 293.6, 261.6, 246.9, 195.9, 164.8, 0, 164.8, 130.8, 0};
-    float times[13] = {0.24, 0.24, 0.24, 0.24, 0.32, 0.32, 0.32, 0.24, 0.24, 0.24, 0.24, 0.24, 0};
-
-    speaker.PlaySong(notes, times);
+//    float notes[13] = {195.9, 293.6, 0, 293.6, 293.6, 261.6, 246.9, 195.9, 164.8, 0, 164.8, 130.8, 0};
+//    float times[13] = {0.24, 0.24, 0.24, 0.24, 0.32, 0.32, 0.32, 0.24, 0.24, 0.24, 0.24, 0.24, 0};
+//
+//    speaker.PlaySong(notes, times);
+//
+    
+    FILE *wave_file;
+    lcd.printf("\n\n\nHello, wave world!\n"); // for debug right now
+    wave_file=fopen("/sd/life.wav","r");
+    waver.play(wave_file);
+    fclose(wave_file);
 
     if (lives == 2) {
         lcd.filled_circle(118, 100, 3, BLACK); // erase the life symbol