Dwayne Dilbeck
/
HW2_3_USB_POT_Mouse
Homework #2 Problem #3
Fork of USBMouse_HelloWorld by
Diff: main.cpp
- Revision:
- 5:2a28b4664b0a
- Parent:
- 3:b8caa902d79e
- Child:
- 6:e35a1f72d90f
--- 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