Submitted by Angela Hsueh, Maya Mardini, Yi Tong Slingshot controller using a force sensor and accelerometer for an Angry Birds clone game.

Dependencies:   LSM303DLHC MMA8451Q PinDetect USBDevice mbed

Fork of hw3_controller by HW3 Controller Team!

Files at this revision

API Documentation at this revision

Comitter:
ahsueh
Date:
Sun Sep 20 17:39:04 2015 +0000
Parent:
3:f3520156ca98
Child:
5:dd93ae8838b4
Commit message:
Most recent code with attempt at using ABS_MOUSE (9/19 evening)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Sep 20 04:10:35 2015 +0000
+++ b/main.cpp	Sun Sep 20 17:39:04 2015 +0000
@@ -17,7 +17,8 @@
 //serial connection to PC via USB
 Serial pc(USBTX, USBRX);
 LSM303DLHC lsm(SDA, SCL);
-USBMouseKeyboard mouseKey;
+USBMouseKeyboard mouseKey(ABS_MOUSE);
+
 
 float prevFsrVal;
 
@@ -104,31 +105,72 @@
     mz1 = 0; mz2 = 0;
 
     float fsrVal;
-    int mouseDistance;
-    int mouseMovement;
+    int mouseDistance = 0;
+    int mouseMovement = 0;
+    mouseKey.move(0,0);
+    int x = 0;
+    int y = 0;
+    
+    // Idea - use ABSOLUTE mouseposition and map fsrVal 0.00- 1.00 to a hardcoded 
+    // mouse position/distance on the screen
     
+        while (1) {
+        fsrVal = fsr.read();
+            mouseMovement = (int) ((fsrVal-prevFsrVal)*10);
+            mouseKey.printf("fsrVal %1.2f movement %0d ", fsrVal, mouseMovement);   
+
+        if (mouseDistance < 100 || (mouseMovement < 0)) {
+            x += mouseMovement;
+            mouseKey.move(x,y); 
+            mouseDistance = mouseDistance + mouseMovement;
+            mouseKey.printf("distance %0d \n", mouseDistance);
+        } else {
+            mouseKey.printf("\n");    
+        }
+        wait(0.2);
+        prevFsrVal = fsrVal;
+
+        if (fsrVal == 0){
+             mouseKey.printf("clear %0d \n", mouseDistance);
+
+             x = 0;
+             y = 0;
+             mouseKey.move(x,y);
+             mouseDistance = 0;
+             wait(0.2);
+        }
+
+    }
+    
+/*
     while (1) {
         fsrVal = fsr.read();
 
-        if (mouseDistance < 100) {
             if (fsrVal < prevFsrVal)
-                mouseMovement = (int) (-fsrVal*8);  
+                mouseMovement = (int) ((fsrVal-prevFsrVal)*10);  
             else          
-                mouseMovement = (int) (fsrVal*8);
-            mouseKey.printf("movement %0d ", mouseMovement);   
+                mouseMovement = (int) (fsrVal*10);
+            mouseKey.printf("fsrVal %1.2f movement %0d ", fsrVal, mouseMovement);   
+            
+        if (mouseDistance < 100 || (mouseMovement < 0)) {
             mouseKey.move(mouseMovement,0); 
             mouseDistance = mouseDistance + mouseMovement;
             mouseKey.printf("distance %0d \n", mouseDistance);
+        } else {
+            mouseKey.printf("\n");    
         }
-        wait(2);
+        wait(0.2);
         prevFsrVal = fsrVal;
+
         if (fsrVal == 0){
              mouseKey.printf("clear %0d \n", mouseDistance);
-             mouseKey.move(-mouseDistance, 0);
+             mouseKey.move(-mouseDistance/2, 0);
              mouseDistance = 0;
-             }
+             wait(0.2);
+        }
+
     }
-
+*/
     while (0) {
         //lsm.read(&ax, &ay, &az, &mx, &my, &mz); //get acceleration