ECE 4180 Final

Dependencies:   mbed wave_player mbed-rtos C12832_lcd 4DGL-uLCD-SE LCD_fonts SDFileSystem

Files at this revision

API Documentation at this revision

Comitter:
yqin70
Date:
Sun Dec 08 02:18:30 2019 +0000
Parent:
20:7d56cdcbc9a5
Commit message:
somewhat done(pushbutton added, has an issue where if you spam the touchpad, it'll increase your score even if there is no bubble).

Changed in this revision

Lane.cpp Show annotated file Show diff for this revision Revisions of this file
Lane.hpp Show annotated file Show diff for this revision Revisions of this file
globals.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7d56cdcbc9a5 -r cbcbb3480cad Lane.cpp
--- a/Lane.cpp	Fri Dec 06 18:00:11 2019 +0000
+++ b/Lane.cpp	Sun Dec 08 02:18:30 2019 +0000
@@ -1,6 +1,5 @@
 #include "Lane.hpp"
 #include "globals.h"
-
 Lane::Lane(int x, int y) {
     xpos = x;
     ypos = y;
@@ -39,10 +38,12 @@
     return pops.empty();
 }
 
-void Lane::checkHit() {
+bool Lane::checkHit() {
     if ((pops.begin())->getYpos() <= 110+20 && (pops.begin())->getYpos() >= 110-20) {
         // black out the bubble and remove it from the lane's vector
         (pops.begin())->clear();
         pops.erase(pops.begin());
+        return true;
     }
+    return false;
 }
\ No newline at end of file
diff -r 7d56cdcbc9a5 -r cbcbb3480cad Lane.hpp
--- a/Lane.hpp	Fri Dec 06 18:00:11 2019 +0000
+++ b/Lane.hpp	Sun Dec 08 02:18:30 2019 +0000
@@ -15,7 +15,7 @@
     void draw();
     void moveDown();
     bool isEmpty();
-    void checkHit();
+    bool checkHit();
     
 private:
     std::vector<Bubble> pops;
diff -r 7d56cdcbc9a5 -r cbcbb3480cad globals.h
--- a/globals.h	Fri Dec 06 18:00:11 2019 +0000
+++ b/globals.h	Sun Dec 08 02:18:30 2019 +0000
@@ -12,7 +12,8 @@
 extern uLCD_4DGL uLCD;
 extern Mutex lcd_mutex;
 
-extern volatile int bubblesDrawn;
-extern volatile int bubblesMissed;
+extern volatile float bubblesDrawn;
+extern volatile float bubblesMissed;
+extern volatile float bubblesHit;
 
 #endif //globals_h
\ No newline at end of file
diff -r 7d56cdcbc9a5 -r cbcbb3480cad main.cpp
--- a/main.cpp	Fri Dec 06 18:00:11 2019 +0000
+++ b/main.cpp	Sun Dec 08 02:18:30 2019 +0000
@@ -36,6 +36,7 @@
 volatile bool homescreen = true;
 volatile bool songchange = false;
 volatile bool playing = false;
+Serial pc(USBTX, USBRX);
 uLCD_4DGL uLCD(p28,p27,p30);
 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
 AnalogIn joy_pot(p16);
@@ -77,9 +78,12 @@
 
 unsigned short **currentBubbles = NULL;
 int bubbleNdx = 0;
-volatile int bubblesDrawn = 0;
-volatile int bubblesMissed = 0;
-
+volatile float bubblesDrawn = 0;
+volatile float bubblesMissed = 0;
+volatile float bubblesHit = 0;
+int key_code;
+int prev_key_code = 0;
+volatile bool touchpadPressed = false;
 
 
 // Thread 1
@@ -180,12 +184,12 @@
             //lcd_mutex.lock();
 //            uLCD.printf("%d", bubblesMissed);
 //            lcd_mutex.unlock();
-            if (bubblesMissed <= 1) {
-                myRGBled = green;
-            } else if (bubblesMissed <= 3) {
+            if (bubblesHit <= 1) {
+                myRGBled = red;
+            } else if (bubblesHit <= 3) {
                 myRGBled = blue;
             } else {
-                myRGBled = red;
+                myRGBled = green;
             }
             Thread::wait(300);
             
@@ -237,6 +241,9 @@
 
 
 void showScore () {
+    
+    lcd_mutex.lock();
+    uLCD.cls();
     uLCD.color(0x00FF00);        // Change text color and set up menu
     uLCD.text_bold(ON);
     uLCD.locate(1,1);
@@ -245,7 +252,7 @@
     uLCD.printf("Thanks for playing Tap Tap Revolution!");
 //    winSound();
     wait(1.5);
-    
+    uLCD.cls();
     uLCD.text_width(1); //4X size text
     uLCD.text_height(1);
     uLCD.text_bold(OFF);
@@ -255,36 +262,54 @@
     uLCD.color(0x00FF00);
     uLCD.locate(2,10);
     
-     float scorePercent = ((bubblesDrawn - bubblesMissed) / bubblesDrawn) * 100;
-    uLCD.printf("%d %", scorePercent);
-    wait(1.2);   
+    float scorePercent = ((bubblesHit) / bubblesDrawn) * 100.0;
+    uLCD.printf("Bubbles Hit %4.2f \n", bubblesHit);
+    uLCD.printf("Bubbles Drawn %4.2f \n", bubblesDrawn);
+    uLCD.printf("Your Score: %4.2f % \n", scorePercent);
+    bubblesHit = 0;
+    bubblesDrawn = 0;
+    //uLCD.printf("%d %", scorePercent);
+    wait(10);   
     uLCD.cls();
     uLCD.locate(5,0);
-    
+    lcd_mutex.unlock();
     Thread::wait(2000);
 }
-
+//touchpad interrupt code
+void fallInterrupt()
+{
+    prev_key_code = key_code;
+    key_code=0;
+    int i=0;
+    int value=mpr121.read(0x00);
+    value +=mpr121.read(0x01)<<8;
+    i=0;
+    //acquires value
+    for (i=0; i<12; i++) {
+        if (((value>>i)&0x01)==1) key_code=i+1;
+    }
+    touchpadPressed = true;
+}
 int main() {
 //<<<<<<< working copy
 //    
-//    uLCD.baudrate(3000000); // set baud rate to max
+    uLCD.baudrate(3000000); // set baud rate to max
 //    
 //=======
 //    interrupt.fall(&fallInterrupt);
 //    interrupt.mode(PullUp);  //for touch keypad
 //    lcd_mutex.lock();
 //    uLCD.baudrate(3000000);
-//    uLCD.cls();
-//    uLCD.media_init();
-//    uLCD.set_sector_address(0x0077, 0x4002);
-//    uLCD.display_video(0,0);
+    uLCD.cls();
+    uLCD.media_init();
+    uLCD.set_sector_address(0x0077, 0x4002);
+    uLCD.display_video(0,0);
 //    wait(4);
 //    lcd_mutex.unlock();
 //>>>>>>> merge rev
-    
     // seed random
     srand (time(NULL));
-    
+
     thread1.start(homescreen_thread);
     thread2.start(joystick_thread);
     thread3.start(pbcontrol_thread);
@@ -296,7 +321,8 @@
     bubbleLanes[0] = new Lane(20,15);
     bubbleLanes[1] = new Lane(60,15);
     bubbleLanes[2] = new Lane(100,15);
-    
+    interrupt.fall(&fallInterrupt);
+    interrupt.mode(PullUp);
     //startup sound?
     
     while(true) {
@@ -359,14 +385,25 @@
                 bubbleLanes[0]->draw();
                 bubbleLanes[1]->draw();
                 bubbleLanes[2]->draw();
+                uLCD.locate(0,0);
+                uLCD.printf("%4.2f", bubblesHit);
                 lcd_mutex.unlock();
                 
+                
                 // TODO: check for hits with capacitive touchpad
                 // if there is a hit, delete the bubble from the dynamic array
                 // replace "true" in the next 3 lines with your logic of when to check for a hit
-//                if (true) bubbleLanes[0]->checkHit();
-//                if (true) bubbleLanes[1]->checkHit();
-//                if (true) bubbleLanes[2]->checkHit();
+                //if touchpad has been pressed, checks if bubble in right spot
+                if(touchpadPressed){
+                //lcd_mutex.lock();
+                //uLCD.printf("%d", key_code);
+                //lcd_mutex.unlock();
+                //pc.printf("Pressed/n");
+                if (key_code == 12) bubblesHit += bubbleLanes[0]->checkHit();
+                if (key_code == 8) bubblesHit += bubbleLanes[1]->checkHit();
+                if (key_code == 4) bubblesHit += bubbleLanes[2]->checkHit();
+                }
+                touchpadPressed = false;
                 
                 // move down all the bubbles, deleting bubbles that are out of bounds if required
                 bubbleLanes[0]->moveDown();
@@ -382,7 +419,7 @@
             }
             
             // uncomment this when gameplay works
-            //showScore();
+            showScore();
             
             // return to homescreen when
             songselect = false;