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: MMA8451Q TSI USBDevice mbed
main.cpp
00001 #include "mbed.h" 00002 #include "USBMouse.h" 00003 #include "MMA8451Q.h" 00004 #include "TSISensor.h" 00005 00006 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00007 00008 USBMouse mouse; 00009 Serial pc(USBTX, USBRX); // tx, rx 00010 00011 int main() 00012 { 00013 float click =0; 00014 int16_t x = 0; 00015 int16_t y = 0; 00016 TSISensor tsi; 00017 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); 00018 00019 while (1) { 00020 x = -10*acc.getAccY(); 00021 y = 10*acc.getAccX(); 00022 00023 mouse.move(x, y); 00024 00025 click=tsi.readPercentage(); 00026 //pc.printf("%f\n",click); 00027 if (click>0.70) 00028 mouse.press(MOUSE_LEFT); 00029 else 00030 mouse.release(MOUSE_LEFT); 00031 00032 if((click<0.30)&&(click>0)) 00033 00034 mouse.press(MOUSE_RIGHT); 00035 else 00036 mouse.release(MOUSE_RIGHT); 00037 00038 wait(0.001); 00039 00040 } 00041 }
Generated on Tue Jul 12 2022 19:11:10 by
1.7.2