Guitar Hero Project on LPC1768 using push buttons, analog joystick. speaker and LCD Display

Dependencies:   mbed wave_player mbed-rtos 4DGL-uLCD-SE SparkfunAnalogJoystick SDFileSystem_OldbutworkswithRTOS PinDetect

Revision:
5:2f09b457f690
Parent:
4:577404e4d53f
Child:
6:4bc137ec1022
--- a/main.cpp	Tue Nov 17 22:07:41 2020 +0000
+++ b/main.cpp	Fri Nov 20 17:19:58 2020 +0000
@@ -5,13 +5,16 @@
 #include "SDFileSystem.h"
 #include "uLCD_4DGL.h"
 #include "PinDetect.h"
+#include "song1.h"
+
+#define sample_freq 8000.0
 //code change
 Mutex lcd_mut;
 //SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
 uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin;
 //AnalogOut DACout(p18);
 //wave_player waver(&DACout);
-
+AnalogOut speaker(p18);
 PinDetect pb_1(p9, PullUp);
 PinDetect pb_2(p10, PullUp);
 PinDetect pb_3(p11, PullUp);
@@ -38,14 +41,26 @@
 DigitalOut myled3(LED3);
 DigitalOut myled4(LED4);
 
+Ticker sampletick;
+
 volatile int Game_State = Game_Over;
 volatile bool draw_enable = true;
 volatile int Speed = Easy; 
 
-FILE *wave_file;
+int i=0;
+void audio_sample ()
+{
+    speaker.write_u16(sound_data[i]);
+    i++;
+    if (i>= NUM_ELEMENTS) {
+        i = 0;
+        sampletick.detach();
+        Game_State = Game_Over;
+    }
+}
 
 void LCD(void const *args) {
-    myled1 = 1;
+
     while(1) {
          switch (Game_State) {
             case Start_Game :
@@ -229,6 +244,10 @@
     }
         
 }
+void startGame() {
+    Game_State = Start_Game;
+    sampletick.attach(&audio_sample, 1.0 / sample_freq);
+}
 
 void pb_1_pressed(void) {
     switch (Game_State) {
@@ -242,7 +261,7 @@
                 break;
             case Choose_Song :
                 draw_enable = true;
-                Game_State = Start_Game;
+                startGame();
                 break;
             case Choose_Difficulty :
                
@@ -273,7 +292,7 @@
                 break;
             case Choose_Song :
                 draw_enable = true;
-                Game_State = Start_Game;
+                startGame();
                 break;
             case Choose_Difficulty :
                
@@ -304,7 +323,7 @@
                 break;
             case Choose_Song :
                 draw_enable = true;
-                Game_State = Start_Game;
+                startGame();
                 break;
             case Choose_Difficulty :
                
@@ -335,7 +354,7 @@
                 break;
             case Choose_Song :
                 draw_enable = true;
-                Game_State = Start_Game;
+                startGame();
                 break;
             case Choose_Difficulty :
                 //not used
@@ -353,7 +372,7 @@
         
 int main()
 {
-    
+    speaker.write_u16(0);
     pb_1.attach_deasserted( &pb_1_pressed );
     pb_2.attach_deasserted( &pb_2_pressed );
     pb_3.attach_deasserted( &pb_3_pressed );