ECE 2035 Summer 2015

Dependencies:   4DGL-uLCD-SE MMA8452 SDFileSystem mbed wave_player

Dependents:   RoboFrogTemplate

Fork of ECE2035_FroggerGame_SUM1025 by Le Tran

Files at this revision

API Documentation at this revision

Comitter:
ece2035ta
Date:
Sun Jul 05 16:55:35 2015 +0000
Parent:
2:7338fd818bab
Child:
4:3fb1d198e9d6
Commit message:
ECE 2035

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jul 05 16:38:47 2015 +0000
+++ b/main.cpp	Sun Jul 05 16:55:35 2015 +0000
@@ -4,6 +4,7 @@
 #include "SDFileSystem.h"
 #include "Shiftbrite.h"
 #include <vector>
+#include "MMA8452.h" 
 
 // Include header files for pacman project
 #include "globals.h"
@@ -16,7 +17,8 @@
 DigitalIn up_pb(p22);    // push bottom
 DigitalIn down_pb(p23);  // push bottom
 uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;)
-
+Serial pc(USBTX,USBRX);     // used by Accelerometer
+MMA8452 acc(p28, p27, 100000); // Accelerometer
 DigitalOut myled(LED1);
 
 int main()
@@ -43,6 +45,7 @@
     uLCD.cls();
     map_init();
     robot_init(0,8);
+    double x_, y_, z_;
     double x=0;
     double y=8;
 
@@ -54,8 +57,9 @@
         /// -[Hint] Implement the code to move Pacman. You could use either push-button or accelerometer. <br>
 
         // [Some hints for user-input detection]
-        //acc.readXYZGravity(&x,&y,&z); //read accelerometer
+        acc.readXYZGravity(&x_,&y_,&z_); //read accelerometer
         uLCD.locate(0,1);
+        
         uLCD.printf("Score x%4.1f ",1); //You could remove this code if you already make the accelerometer work.
         /// -[Hint] Here is a simple way to utilize the readings of accelerometer:
         ///         If x is larger than certain value (ex:0.3), then make the Pacman move right.
@@ -67,44 +71,6 @@
 
             /// 3. Update the Pacman on the screen
             /// -[Hint] You could update the position of Pacman (draw it on the screen) here based on the user-input at step 2. <br>
-            if (!up_pb) {                                        //MOVE UP
-                robot_clear(x,y);
-                map_draw_grid(x,y);
-                if (y!=0) {
-                    y=y-1;
-                } else {
-                    y=15;
-                }
-                wait(0.1);
-                robot_init(x,y);
-            } else if(!down_pb) {                                    //MOVE DOWN
-                robot_clear(x,y);
-                map_draw_grid(x,y);
-                if(y!=15) {
-                    y=y+1;
-                } else {
-                    y=0;
-                }
-                wait(0.1);
-                robot_init(x,y);
-            } else if (!left_pb) {                                  //MOVE LEFT
-                robot_clear(x,y);
-                map_draw_grid(x,y);
-                if (x!=0) {
-                    x-=1;
-                }
-                wait(0.1);
-                robot_init(x,y);
-
-            } else if(!right_pb) {                                  //MOVE RIGHT
-                robot_clear(x,y);
-                map_draw_grid(x,y);
-                if (x!=16) {
-                    x+=1;
-                }
-                wait(0.1);
-                robot_init(x,y);
-            }