W R / Mbed 2 deprecated 4180_Final_Project_old

Dependencies:   mbed wave_player mbed-rtos 4180Final SDFileSystem

Revision:
4:8331c1239f6a
Parent:
3:927028389e55
Child:
5:1e8b48d6682b
--- a/play.cpp	Mon Apr 27 05:25:27 2020 +0000
+++ b/play.cpp	Mon Apr 27 19:30:53 2020 +0000
@@ -1,109 +1,109 @@
-//#include "mbed.h"
-//#include "uLCD_4DGL.h"
-//#include "Nav_Switch.h"
-////#include "SDFileSystem.h"
-//#include "microphone.h"
-////#include  "rtos.h"
-//
-//Nav_Switch myNav(p9, p6, p7, p5, p8); //pin order on Sparkfun breakout
-//uLCD_4DGL uLCD(p28, p27, p30); // serial tx, serial rx, reset pin; 
-//PwmOut myled(LED1);
-////SDFileSystem sd(p11, p12, p13, p10, "sd");
-//microphone mymic1(p15);
-//AnalogIn pot(p16);
-//
-//int rounds = 3;
-//int round_time = 15; //seconds 
-//int curRound = 1;
-//int score1 = 0;
-//int score2 = 0;
-//int scores1[7] = {0};
-//int scores2[7] = {0};
-//int curTime = 0;
-//int wonRnds1 = 0;
-//int wonRnds2 = 0;
-//int highScoresArr[10] = {100, 90, 83, 73, 64, 54, 44, 34, 24, 14};
-//int s = 0;
-//int timer = 0;
-//int tick = 0; 
-//
-//Timer play_time; 
-// 
-// 
-//void play_draw(){
-//     uLCD.background_color(GREEN);
-//     uLCD.cls();
-//     uLCD.filled_rectangle(0, 0, 200, 15, RED);
-//     // header
-//     uLCD.color(BLACK);
-//     uLCD.locate(5,0);
-//     uLCD.text_height(2);
-//     uLCD.text_width(2);
-//     uLCD.textbackground_color(RED);
-//     uLCD.printf("PLAY");
-//     uLCD.text_height(1);
-//     uLCD.text_width(1);
-//     uLCD.locate(14,1);
-//     uLCD.printf("Rnd%1d", curRound);
-//     // Scores headers
-//     uLCD.textbackground_color(GREEN);
-//     uLCD.color(BLUE);
-//     uLCD.locate(5,3);
-//     uLCD.printf("Player 1:");
-//     uLCD.color(PURPLE);
-//     uLCD.locate(5,11);
-//     uLCD.printf("Player 2:");
-//     // Scores
-//     uLCD.text_height(4);
-//     uLCD.text_width(4);
-//   
-//} 
-//
-//void update_LEDS() {
-// 
-// }
-// 
-//void play() {
-//     play_draw(); 
-//     play_time.reset(); 
-//     play_time.start(); 
-//     while (play_time.read() < round_time*1000) {
-//        if (myNav.fire()) { //open pause menu 
-//            uLCD.filled_rectangle(60, 68, 65, 82, GREEN); //the pause draw functions shoudl be contained within pause
-//            uLCD.filled_rectangle(70, 68, 75, 82, GREEN);
-//            wait(.1);
-//            //pause();
-//        }
-//        
-//        if (int(play_time.read()) % 8 == 0) { //Use an 8kHz audio sample rate (phone quality audio);
-//            tick = get_sound(); // this should be added to every iter
-//            score1 += tick; 
-//            //score2 = curTime+2000;
-//            
-//            ///DRAWS SCORES ON SCREEN
-//            uLCD.color(BLUE);
-//            uLCD.locate(0,1);
-//            uLCD.printf("%4d", tick);
-//            uLCD.color(PURPLE);
-//            uLCD.locate(0,3);
-//            uLCD.printf("%4d", score1);
-//                
-//                /*
-//            // Time bar
-//            double roundTime = 15.0;  // in secs
-//            int length = (int) ( (double)curTime / roundTime * 127.0);
-//            uLCD.filled_rectangle(0, 65, length, 85, DGREEN);
-//            if (length >= 127) {
-//                nextRound();
-//            }
-//            curTime++;
-//            */
-//        }
-//        timer++;
-//    }
-//}
-// 
-//int main()
-//{
-//    play();
-//}
+#include "mbed.h"
+#include "uLCD_4DGL.h"
+#include "Nav_Switch.h"
+//#include "SDFileSystem.h"
+#include "microphone.h"
+//#include  "rtos.h"
+
+Nav_Switch myNav(p9, p6, p7, p5, p8); //pin order on Sparkfun breakout
+uLCD_4DGL uLCD(p28, p27, p30); // serial tx, serial rx, reset pin; 
+PwmOut myled(LED1);
+//SDFileSystem sd(p11, p12, p13, p10, "sd");
+microphone mymic1(p15);
+AnalogIn pot(p16);
+
+int rounds = 3;
+int round_time = 15; //seconds 
+int curRound = 1;
+int score1 = 0;
+int score2 = 0;
+int scores1[7] = {0};
+int scores2[7] = {0};
+int curTime = 0;
+int wonRnds1 = 0;
+int wonRnds2 = 0;
+int highScoresArr[10] = {100, 90, 83, 73, 64, 54, 44, 34, 24, 14};
+int s = 0;
+int timer = 0;
+int tick = 0; 
+
+Timer play_time; 
+ 
+ 
+void play_draw(){
+     uLCD.background_color(GREEN);
+     uLCD.cls();
+     uLCD.filled_rectangle(0, 0, 200, 15, RED);
+     // header
+     uLCD.color(BLACK);
+     uLCD.locate(5,0);
+     uLCD.text_height(2);
+     uLCD.text_width(2);
+     uLCD.textbackground_color(RED);
+     uLCD.printf("PLAY");
+     uLCD.text_height(1);
+     uLCD.text_width(1);
+     uLCD.locate(14,1);
+     uLCD.printf("Rnd%1d", curRound);
+     // Scores headers
+     uLCD.textbackground_color(GREEN);
+     uLCD.color(BLUE);
+     uLCD.locate(5,3);
+     uLCD.printf("Player 1:");
+     uLCD.color(PURPLE);
+     uLCD.locate(5,11);
+     uLCD.printf("Player 2:");
+     // Scores
+     uLCD.text_height(4);
+     uLCD.text_width(4);
+   
+} 
+
+void update_LEDS() {
+ 
+ }
+ 
+void play() {
+     play_draw(); 
+     play_time.reset(); 
+     play_time.start(); 
+     while (play_time.read() < round_time*1000) {
+        if (myNav.fire()) { //open pause menu 
+            uLCD.filled_rectangle(60, 68, 65, 82, GREEN); //the pause draw functions shoudl be contained within pause
+            uLCD.filled_rectangle(70, 68, 75, 82, GREEN);
+            wait(.1);
+            //pause();
+        }
+        
+        if (int(play_time.read()) % 8 == 0) { //Use an 8kHz audio sample rate (phone quality audio);
+            tick = get_sound(); // this should be added to every iter
+            score1 += tick; 
+            //score2 = curTime+2000;
+            
+            ///DRAWS SCORES ON SCREEN
+            uLCD.color(BLUE);
+            uLCD.locate(0,1);
+            uLCD.printf("%4d", tick);
+            uLCD.color(PURPLE);
+            uLCD.locate(0,3);
+            uLCD.printf("%4d", score1);
+                
+                /*
+            // Time bar
+            double roundTime = 15.0;  // in secs
+            int length = (int) ( (double)curTime / roundTime * 127.0);
+            uLCD.filled_rectangle(0, 65, length, 85, DGREEN);
+            if (length >= 127) {
+                nextRound();
+            }
+            curTime++;
+            */
+        }
+        timer++;
+    }
+}
+ 
+int main()
+{
+    play();
+}