NONE

Dependencies:   MMA8451Q USBDevice mbed

Fork of USBMouse_HelloWorld by Samuel Mokrani

Files at this revision

API Documentation at this revision

Comitter:
naray23
Date:
Fri Jul 07 01:07:38 2017 +0000
Parent:
4:26ecbbc27530
Commit message:
NONE

Changed in this revision

MMA8451Q.lib 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 26ecbbc27530 -r 15f41f12f4eb MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Fri Jul 07 01:07:38 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 26ecbbc27530 -r 15f41f12f4eb main.cpp
--- a/main.cpp	Fri Mar 01 13:26:13 2013 +0000
+++ b/main.cpp	Fri Jul 07 01:07:38 2017 +0000
@@ -1,20 +1,36 @@
 #include "mbed.h"
 #include "USBMouse.h"
+#include "MMA8451Q.h"
+
+#if   defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
+  PinName const SDA = PTE25;
+  PinName const SCL = PTE24;
+#elif defined (TARGET_KL05Z)
+  PinName const SDA = PTB4;
+  PinName const SCL = PTB3;
+#elif defined (TARGET_K20D50M)
+  PinName const SDA = PTB1;
+  PinName const SCL = PTB0;
+#else
+  #error TARGET NOT DEFINED
+#endif
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
 
 USBMouse mouse;
 
 int main() {
-    int16_t x = 0;
-    int16_t y = 0;
-    int32_t radius = 10;
-    int32_t angle = 0;
-
+    int x, y,z;
+    
+    
+    MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
     while (1) {
-        x = cos((double)angle*3.14/180.0)*radius;
-        y = sin((double)angle*3.14/180.0)*radius;
+        
+        x =1.0f- abs(10*acc.getAccX());
+        y = 1.0f- abs(10*acc.getAccY());
+        z = 1.0f-abs(10*acc.getAccZ());
         
         mouse.move(x, y);
-        angle += 3;
         wait(0.001);
     }
 }
\ No newline at end of file