Homework #2 Problem #3

Dependencies:   USBDevice mbed

Fork of USBMouse_HelloWorld by Samuel Mokrani

Files at this revision

API Documentation at this revision

Comitter:
jakowisp
Date:
Wed Jun 26 03:00:13 2013 +0000
Parent:
4:26ecbbc27530
Child:
6:e35a1f72d90f
Commit message:
Initial working version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Mar 01 13:26:13 2013 +0000
+++ b/main.cpp	Wed Jun 26 03:00:13 2013 +0000
@@ -1,20 +1,32 @@
 #include "mbed.h"
 #include "USBMouse.h"
 
-USBMouse mouse;
+USBMouse mouse(ABS_MOUSE);
+AnalogIn potA(p20);
+AnalogIn potB(p19);
+
+BusIn button(p12,p15,p13,p16);
+DigitalIn fire(p14);
+int lastButtonState=0,buttonChanged=0,buttonState=0;
+
+float x,y; 
+
 
 int main() {
-    int16_t x = 0;
-    int16_t y = 0;
-    int32_t radius = 10;
-    int32_t angle = 0;
-
     while (1) {
-        x = cos((double)angle*3.14/180.0)*radius;
-        y = sin((double)angle*3.14/180.0)*radius;
+    #ifdef FLOATPOT
+        x= 0x7fff * potA.read();
+        y= 0x7fff * potB.read();
+    #else
+        x=  ( potA.read_u16() & 0xfff0 ) >> 1;
+        y=  ( potB.read_u16() & 0xfff0 ) >> 1;  
+    #endif   
+        buttonState =  button.read() & 0x7;
+        buttonChanged =  buttonState ^ lastButtonState;
+        mouse.move(x, y);
+        mouse.press(buttonState & buttonChanged);
+        mouse.release(!buttonState & buttonChanged);
         
-        mouse.move(x, y);
-        angle += 3;
         wait(0.001);
     }
 }
\ No newline at end of file