Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXOS8700Q USBDevice mbed
Diff: main.cpp
- Revision:
- 2:0053ee456979
- Parent:
- 1:3c6efa018b57
diff -r 3c6efa018b57 -r 0053ee456979 main.cpp
--- a/main.cpp Sat Mar 21 13:52:35 2015 +0000
+++ b/main.cpp Sat Mar 21 15:54:47 2015 +0000
@@ -2,12 +2,24 @@
#include "USBMouseKeyboard.h"
#include "FXOS8700Q.h"
-USBMouseKeyboard key_mouse; // Use USBMouseKeyboard which emulates USB mouse & keyboard
-FXOS8700Q_acc acc( PTB3, PTB2, FXOS8700CQ_SLAVE_ADDR2); // Use accelerometer
+USBMouseKeyboard key_mouse; // Use USBMouseKeyboard which emulates USB mouse & keyboard
+FXOS8700Q_acc acc( PTB3, PTB2, FXOS8700CQ_SLAVE_ADDR2 ); // Use accelerometer
MotionSensorDataUnits acc_data;
DigitalIn sw2(SW2);
DigitalIn sw3(SW3);
+int calcMouseMovement(float f) {
+ if( f > 0.3f ) {
+ // Board is listing to the right or to the front
+ return 10;
+ } else if( f < -0.3f ) {
+ // Board is listing to the left or to the back
+ return -10;
+ } else {
+ return 0;
+ }
+}
+
int main(void) {
acc.enable();
@@ -16,22 +28,11 @@
acc.getAxis(acc_data);
float x = acc_data.x; // Substitute x for x-axis value of accelerometer
float y = acc_data.y; // Substitute y for y-axis value of accelerometer
-
- if( x > 0.3f ) {
- // Board is listing to the right
- key_mouse.move(10, 0); // Move the mouse cursor +10 in x-axis direction
- } else if( x < -0.3 ) {
- // Board is listing to the left
- key_mouse.move(-10, 0); // Move the mouse cursor -10 in x-axis direction
- }
- if( y > 0.3f ){
- // Board is listing to the front
- key_mouse.move(0, -10); // Move the mouse cursor +10 in y-axis direction
- } else if( y < -0.3 ) {
- // Board is listing to the back
- key_mouse.move(0, 10); // Move the mouse cursor -10 in y-axis direction
- }
+ key_mouse.move(calcMouseMovement(x), 0); // Move the mouse cursor in x-axis direction
+ key_mouse.move(0, calcMouseMovement(-y)); // Move the mouse cursor in y-axis direction
+ printf("%f => key_mouse.move(%d, 0)\r\n", x, calcMouseMovement(x));
+ printf("%f => key_mouse.move(0, %d)\r\n", y, calcMouseMovement(y));
if( sw2 == 1 ) {
// SW2 is not pressed