Test application for Freedom KL25Z, mouse driven by accelerometer and click with TSI interface
Dependencies: Airmouse MMA8451Q TSI USBDevice mbed
Fork of Airmouse by
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 Sat Jul 30 2022 20:30:30 by 1.7.2