code yo

Dependencies:   MMA8451Q USBDevice mbed

Fork of idd_graph_sensor by Interactive Device Design

Files at this revision

API Documentation at this revision

Comitter:
cdierk
Date:
Thu Sep 25 19:10:16 2014 +0000
Parent:
0:c9bb3c9d5ce8
Commit message:
First commit!

Changed in this revision

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Thu Sep 25 19:10:16 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#5bf05f9b3c7b
--- a/main.cpp	Wed Sep 17 07:59:48 2014 +0000
+++ b/main.cpp	Thu Sep 25 19:10:16 2014 +0000
@@ -1,5 +1,8 @@
 #include "mbed.h"
 #include "MMA8451Q.h"
+#include "USBMouse.h"
+
+USBMouse mouse;
 
 // define I2C Pins and address for KL25Z. Taken from default sample code.
 PinName const SDA = PTE25;
@@ -9,17 +12,63 @@
 //serial connection to PC via USB
 Serial pc(USBTX, USBRX);
 
+DigitalIn button1(D8);
+DigitalIn button2(D7);
+
 int main(void)
 {
+    AnalogIn xPin(A3);
+    AnalogIn yPin(A4);
+    AnalogIn zPin(A5);
+    button1.mode(PullUp);
+    button2.mode(PullUp);
+    
     //configure on-board I2C accelerometer on KL25Z
     MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
     
-    float x;
+    Serial pc(USBTX, USBRX);
     
     while (true) {
-        x = acc.getAccX(); //get acceleration
-        pc.printf("%1.2f\n", x); //print ascii-encoded float to serial port
-        wait(0.05f); // wait 50ms (20Hz update rate)
+        
+        float xValue = xPin.read();
+        float yValue = yPin.read();
+        float zValue = zPin.read();
+        pc.printf("%1.2f, %1.2f, %1.2f \r\n", xValue - 0.48, yValue - 0.44, zValue);
+        mouse.move(-150 * (xValue - 0.48), 150 * (yValue - 0.44));
+        
+        if (!button1) {
+            mouse.click(MOUSE_LEFT);
+        }
+        if (!button2) {
+            
+            float yValueMax = yPin.read();
+            yValue = yPin.read();
+            while(true){
+                if (yValue > yValueMax){
+                    yValueMax = yValue;
+                    yValue = yPin.read();
+                } else if ((yValue + .30) <= yValueMax){
+                    mouse.click(MOUSE_LEFT);
+                    break;   
+                } else {
+                    yValue = yPin.read();
+                }
+            }
+            /*while(true){
+                if (yValue <= .50){
+                    yValue = yPin.read();
+                } else {
+                    while(true){
+                        yValue = yPin.read();
+                        if (yValue < .40){
+                            mouse.click(MOUSE_LEFT);
+                            break;
+                        }
+                    }
+                }
+                break;
+            }*/
+        }
     }
 }