Test application for Freedom KL25Z, mouse driven by accelerometer and click with TSI interface

Dependencies:   MMA8451Q TSI USBDevice mbed

Fork of Airmouse by Frederic Thierry

Files at this revision

API Documentation at this revision

Comitter:
tono88
Date:
Thu Jun 16 01:06:05 2016 +0000
Parent:
0:a7df8e8cc00c
Commit message:
Lab5

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r a7df8e8cc00c -r e92bdcecbfb5 main.cpp
--- a/main.cpp	Mon Jun 24 23:23:47 2013 +0000
+++ b/main.cpp	Thu Jun 16 01:06:05 2016 +0000
@@ -1,18 +1,22 @@
 #include "mbed.h"
 #include "USBMouse.h"
+#include "USBKeyboard.h"
 #include "MMA8451Q.h"
 #include "TSISensor.h"
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 
 USBMouse mouse;
+USBKeyboard keyboard;
 Serial pc(USBTX, USBRX); // tx, rx
 
+
 int main()
 {
     float click =0;
     int16_t x = 0;
     int16_t y = 0;
+    int16_t corrimiento = 0;
     TSISensor tsi;
     MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
 
@@ -20,22 +24,35 @@
         x = -10*acc.getAccY();
         y = 10*acc.getAccX();
 
-        mouse.move(x, y);
+       // pc.putc(x);
+        //mouse.move(x, y);
     
         click=tsi.readPercentage();
         //pc.printf("%f\n",click);
+        
+        
+        if (y>-5)
+            corrimiento=0;
+        else
+            corrimiento =3;
+        
         if (click>0.70)
-            mouse.press(MOUSE_LEFT);
-            else
-            mouse.release(MOUSE_LEFT);
+            //mouse.press(MOUSE_LEFT);
             
-          if((click<0.30)&&(click>0))
+            keyboard._putc(97+corrimiento);
+           // else
+           // mouse.release(MOUSE_LEFT);
             
-            mouse.press(MOUSE_RIGHT);
-            else
-            mouse.release(MOUSE_RIGHT);
+          if((click<0.60)&&(click>0.30))
+            keyboard._putc(98+corrimiento);
+            //mouse.press(MOUSE_RIGHT);
+            //else
+            //mouse.release(MOUSE_RIGHT);
             
-        wait(0.001);
+            if((click<0.30)&&(click>0))
+            keyboard._putc(99+corrimiento);
+            
+        wait(0.1);
        
     }
 }
\ No newline at end of file