w4spiusbmouse

Dependencies:   FXOS8700Q USBDevice mbed

Committer:
occle
Date:
Thu Jan 12 15:46:35 2017 +0000
Revision:
0:5030214d976d
w4spiusbmouse

Who changed what in which revision?

UserRevisionLine numberNew contents of line
occle 0:5030214d976d 1 #include "mbed.h"
occle 0:5030214d976d 2 #include "USBMouse.h"
occle 0:5030214d976d 3 #include "FXOS8700Q.h"
occle 0:5030214d976d 4
occle 0:5030214d976d 5 //I2C lines for FXOS8700Q accelerometer/magnetometer
occle 0:5030214d976d 6 FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
occle 0:5030214d976d 7 DigitalIn leftbutton(SW2); //SW2 will be assigned to the left mouse button
occle 0:5030214d976d 8 DigitalIn rightbutton(SW3); //SW3 will be assigned to the right mouse button
occle 0:5030214d976d 9
occle 0:5030214d976d 10
occle 0:5030214d976d 11 USBMouse mouse;
occle 0:5030214d976d 12
occle 0:5030214d976d 13 int main()
occle 0:5030214d976d 14 {
occle 0:5030214d976d 15 acc.enable(); //enable the accelerometer
occle 0:5030214d976d 16 float faX, faY, faZ;
occle 0:5030214d976d 17 int16_t x = 0;
occle 0:5030214d976d 18 int16_t y = 0;
occle 0:5030214d976d 19
occle 0:5030214d976d 20 while (1)
occle 0:5030214d976d 21 {
occle 0:5030214d976d 22 //acc.getAxis(acc_data);
occle 0:5030214d976d 23 acc.getX(&faX);
occle 0:5030214d976d 24 acc.getY(&faY);
occle 0:5030214d976d 25 acc.getZ(&faZ);
occle 0:5030214d976d 26 x = 10*faX;
occle 0:5030214d976d 27 y = 10*faY;
occle 0:5030214d976d 28
occle 0:5030214d976d 29 mouse.move(x, y); //move mouse dependant on the postion of the rotation of the mbed
occle 0:5030214d976d 30
occle 0:5030214d976d 31 if(leftbutton==0){
occle 0:5030214d976d 32 mouse.press(MOUSE_LEFT);
occle 0:5030214d976d 33 }
occle 0:5030214d976d 34 else{mouse.release(MOUSE_LEFT);}
occle 0:5030214d976d 35
occle 0:5030214d976d 36 if(rightbutton==0){
occle 0:5030214d976d 37 mouse.press(MOUSE_RIGHT);
occle 0:5030214d976d 38 }
occle 0:5030214d976d 39 else{mouse.release(MOUSE_RIGHT);}
occle 0:5030214d976d 40
occle 0:5030214d976d 41 wait(0.001); //updates position every 0.001 seconds
occle 0:5030214d976d 42 }
occle 0:5030214d976d 43 }