ECE2035 Project 2
Dependencies: mbed mbed-rtos SDFileSystem
Diff: main.cpp
- Revision:
- 7:95db0d89fbac
- Parent:
- 5:b9b7993823e1
- Child:
- 9:f1d34ef049c5
--- a/main.cpp Thu Apr 08 16:44:39 2021 +0000 +++ b/main.cpp Fri Apr 09 13:49:01 2021 +0000 @@ -20,11 +20,13 @@ #include "mbed.h" #include "doubly_linked_list.h" #include "rtos.h" +#include "Speaker.h" //For sound components //AnalogOut DACout(p18); -PwmOut pwmout(p26); +//PwmOut pwmout(p26); //PwmOut speaker(p25); +Speaker speak(p25); //wave_player waver(&DACout); //SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sck, cs @@ -36,6 +38,7 @@ bool exitFlag = false; int score = 0; Thread thread; +int sound = 0; // ===User implementations start=== int fruit_contact(void); // iterate through fruits and see if any collided @@ -66,8 +69,8 @@ set_random_seed(t); wait(0.3); //mkdir("/sd/wavfiles", 0777); - pwmout.period(1.0/4000.0); - playSound("/sd/wavfiles/SAMPLE8.wav");//test the sound convert to thread + //pwmout.period(1.0/4000.0); + //playSound();//test the sound convert to thread //wait(0.1); //playNotes(); @@ -77,7 +80,6 @@ player_init(); compost_pile_init(); pc.printf("Initialization complete\n"); - thread.start(playSound); //uLCD.printf("Score: %d", score); while(1) @@ -103,6 +105,9 @@ if (!inputs.b3) { + //speak.PlayNote(400.0, 0.1, 0.1); + sound = 1; + thread.start(playSound); player_throw(); } @@ -175,7 +180,9 @@ } player_knife_return(); score++; - pc.printf("score: %d\n", score); + //pc.printf("score: %d\n", score); + sound = 2; + thread.start(playSound); return 1; } curr = curr->next; @@ -225,7 +232,20 @@ { //open wav file FILE *wave_file; - char* wav = "/sd/wavfiles/SAMPLE8.wav"; + char* wav; + + switch (sound) { + case 1: + wav = "/sd/wavfiles/FIRE.wav"; + break; + case 2: + wav = "/sd/wavfiles/SCORE.wav"; + break; + default: + break; + + } + wave_file=fopen(wav,"r"); //waver.set_verbosity(1); @@ -297,13 +317,16 @@ } void set_random_seed(Timer t) { + //thread.start(playSound); GameInputs inputs; t.start(); uLCD.printf("Push any button to start.\n"); while(1){ inputs = read_inputs(); - if (!inputs.b1 || !inputs.b2 || !inputs.b3) break; - } + if (!inputs.b1 || !inputs.b2 || !inputs.b3) { + break; + } + } uLCD.cls(); t.stop(); int seed = t.read_ms();