James Heavey / Mbed 2 deprecated EL17JH

Dependencies:   mbed

Revision:
15:b867a6620f96
Parent:
9:f6f0f39538c7
Child:
16:1761dfe801af
--- a/Paddle/Paddle.cpp	Tue Apr 23 16:13:17 2019 +0000
+++ b/Paddle/Paddle.cpp	Tue Apr 23 17:09:47 2019 +0000
@@ -1,5 +1,7 @@
 #include "Paddle.h"
 
+FXOS8700CQ acc(I2C_SDA,I2C_SCL);
+
 // nothing doing in the constructor and destructor
 Paddle::Paddle()
 {
@@ -20,6 +22,7 @@
     _speed = 1;  // default speed
     _score = 0;  // start score from zero
     _lives = 6;
+    //_tilt? = false; use to choose between motion methods
 
 }
 
@@ -31,15 +34,34 @@
 
 void Paddle::update(Direction d,float mag)
 {
-    _speed = int(mag*10.0f);  // scale is arbitrary, could be changed in future
+//    //if (_tilt == false) {
+//    _speed = int(mag*10.0f);  // scale is arbitrary, could be changed in future
+
+//    // update y value depending on direction of movement
+//    // North is decrement as origin is at the top-left so decreasing moves up
+//    if (d == W) {
+//        _x-=_speed;
+//    } else if (d == E) {
+//        _x+=_speed;
+//    }
+
+//    // check the y origin to ensure that the paddle doesn't go off screen
+//    if (_x < 1) {
+//        _x = 1;
+//    }
+//    if (_x > WIDTH - _width - 1) {
+//        _x = WIDTH - _width - 1;
+//    }
+    
+    //else if (_tilt =+ true) {
+    
+    Data values = acc.get_values();
+    float roll_rad = atan2(values.ay,values.az);
+    _speed = int((roll_rad*(360/3.14159265))*0.3f);  // scale is arbitrary, could be changed in future
 
     // update y value depending on direction of movement
     // North is decrement as origin is at the top-left so decreasing moves up
-    if (d == W) {
-        _x-=_speed;
-    } else if (d == E) {
-        _x+=_speed;
-    }
+    _x -= _speed;
 
     // check the y origin to ensure that the paddle doesn't go off screen
     if (_x < 1) {