Presenting to you the code for Smart Mouse developed using accelerometer and capacitive touch slider in FRDM KL25Z

Dependencies:   MMA8451Q TSI USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
vinithias
Date:
Sun Mar 06 10:57:37 2016 +0000
Commit message:
IC

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
USBDevice.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 4b36fd6e6a4a MMA8451Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Sun Mar 06 10:57:37 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
diff -r 000000000000 -r 4b36fd6e6a4a TSI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Sun Mar 06 10:57:37 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/mbed/code/TSI/#1a60ef257879
diff -r 000000000000 -r 4b36fd6e6a4a USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Sun Mar 06 10:57:37 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/USBDevice/#d17693b10ae6
diff -r 000000000000 -r 4b36fd6e6a4a main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Mar 06 10:57:37 2016 +0000
@@ -0,0 +1,91 @@
+#include "mbed.h"
+#include "MMA8451Q.h"
+#include "USBMouse.h"
+#include "TSISensor.h"
+#include "USBSerial.h"
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+USBMouse mouse;
+TSISensor tsi;
+
+
+
+int main(void)
+ {
+    MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+    PwmOut gled(LED_GREEN);
+    PwmOut bled(LED_BLUE);
+    bool TSI_Pressed = false;
+    int ButtonPressed = 0; 
+    //1=MOUSE_LEFT 2=MOUSE_RIGHT 4=MOUSE_MIDDLE
+    unsigned int TSI_Press_Time = 0;
+
+    while (true) 
+    { // tsi mouse clicks
+        if (tsi.readPercentage() < 0.01) 
+        { 
+            if (TSI_Pressed == true) 
+            {
+                if (TSI_Press_Time < 250) 
+                {
+                    if (ButtonPressed == 1) 
+                    {
+                        mouse.click(MOUSE_LEFT);
+                    }
+                    else if (ButtonPressed == 2) 
+                    {
+                        mouse.click(MOUSE_RIGHT);
+                    }
+                    else if (ButtonPressed == 4) 
+                    {
+                        mouse.click(MOUSE_MIDDLE);
+                    }
+                }
+                TSI_Pressed = false;
+                TSI_Press_Time = 0;
+            }
+        }
+        else if (tsi.readPercentage() < 0.25) 
+        { 
+            if (TSI_Pressed == false) 
+            {
+                TSI_Pressed = true;
+                ButtonPressed = 2;
+            }
+        }
+        else if (tsi.readPercentage() < 0.5) 
+        { 
+            if (TSI_Pressed == false) 
+            {
+                TSI_Pressed = true;
+                ButtonPressed = 4;
+            }
+        } 
+        else 
+        {
+            if (TSI_Pressed == false) 
+            {
+                TSI_Pressed = true;
+                ButtonPressed = 1;
+            }
+        }
+        if (TSI_Pressed == true)
+         {
+            TSI_Press_Time++;
+        }
+        
+        // mouse control
+        float AccY = acc.getAccX();
+        float AccX = acc.getAccY();
+        bled = 1.0 - abs(AccX);
+        gled = 1.0 - abs(AccY);
+        signed char x = AccX * -10;
+        signed char y = AccY * 10;
+        mouse.move(x, y);
+        wait(0.001);
+        
+       
+        
+    }
+}
+
diff -r 000000000000 -r 4b36fd6e6a4a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Mar 06 10:57:37 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file