In-air mouse using Freedom board

Dependencies:   MMA8451Q TSI USBDevice mbed

Fork of USBMouse_HelloWorld by Samuel Mokrani

First project using (and testing out) the Freescale Freedom board.

Plug the USB (not SDA) connector into your machine.

Tilt the board to move the cursor, and use the touch sensor for left and right click.

Files at this revision

API Documentation at this revision

Comitter:
User_4574
Date:
Sun Mar 03 16:01:33 2013 +0000
Parent:
4:26ecbbc27530
Commit message:
First Commit

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
TSI.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Sun Mar 03 16:01:33 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Sun Mar 03 16:01:33 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/TSI/#507b1f67804b
--- a/main.cpp	Fri Mar 01 13:26:13 2013 +0000
+++ b/main.cpp	Sun Mar 03 16:01:33 2013 +0000
@@ -1,20 +1,53 @@
 #include "mbed.h"
 #include "USBMouse.h"
+#include "MMA8451Q.h"
+#include "TSISensor.h"
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
 
 USBMouse mouse;
+MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+TSISensor tsi;
+
+typedef enum {NONE = 0, LEFT, RIGHT} Click;
 
 int main() {
-    int16_t x = 0;
-    int16_t y = 0;
-    int32_t radius = 10;
-    int32_t angle = 0;
+    int16_t x = 0, y = 0;
+    float t;
+    Click in_click = NONE;
 
     while (1) {
-        x = cos((double)angle*3.14/180.0)*radius;
-        y = sin((double)angle*3.14/180.0)*radius;
+        t = acc.getAccX();
+        t *= 10/1.5;
+        y = (int16_t) t;
+        
+        t = acc.getAccY();
+        t *= 10/1.5;
+        x = - (int16_t) t;
+        
+        t = tsi.readPercentage();
+        
+        if (in_click == NONE) {
+            if (t > 0.6) {
+                mouse.press(MOUSE_LEFT);
+                in_click = LEFT;
+            } else if (t > 0.1) {
+                mouse.press(MOUSE_RIGHT);
+                in_click = RIGHT;
+            }
+        } else if (in_click == LEFT) {
+            if (t <= 0.6) {
+                mouse.release(MOUSE_LEFT);
+                in_click = NONE;
+            }
+        } else {
+            if (t > 0.6 || t <= 0.1) {
+                mouse.release(MOUSE_RIGHT);
+                in_click = NONE;
+            }
+        }
         
         mouse.move(x, y);
-        angle += 3;
         wait(0.001);
     }
 }
\ No newline at end of file