Test application for Freedom KL25Z, mouse driven by accelerometer and click with TSI interface
Dependencies: MMA8451Q TSI USBDevice mbed
Fork of Airmouse by
Diff: main.cpp
- Revision:
- 1:647d6636eb03
- Parent:
- 0:a7df8e8cc00c
--- a/main.cpp Mon Jun 24 23:23:47 2013 +0000 +++ b/main.cpp Thu Jun 09 01:35:29 2016 +0000 @@ -2,38 +2,66 @@ #include "USBMouse.h" #include "MMA8451Q.h" #include "TSISensor.h" - +#include "USBMouseKeyboard.h" #define MMA8451_I2C_ADDRESS (0x1d<<1) - +#include "USBKeyboard.h" USBMouse mouse; Serial pc(USBTX, USBRX); // tx, rx - +USBKeyboard key; int main() { +//Debe cambiar su air mouse a un simple keyboard. Debe poder ingresar 3 teclas del teclado “a”, “b” y “c”. +//Para ello le recomendamos segmentar el slider en 3 posiciones, una para cada letra, y detectar un toque en cada área, luego mandar esa tecla como un caracter. +//Puede utilizar su imaginación para mejorar la interfaz. float click =0; int16_t x = 0; int16_t y = 0; TSISensor tsi; MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); - + while (1) { x = -10*acc.getAccY(); y = 10*acc.getAccX(); - + pc.printf("%f\n",x); mouse.move(x, y); - + click=tsi.readPercentage(); //pc.printf("%f\n",click); - if (click>0.70) - mouse.press(MOUSE_LEFT); - else - mouse.release(MOUSE_LEFT); + if (click>0.70){ + if(y>5){ + key.putc(97); + wait(0.3); + } + if(y==0){ + key.putc(100); + wait(0.3); + } + } + if((click<0.60)&&(click>0.30)){ - if((click<0.30)&&(click>0)) + if(y>5){ + key.putc(98); + wait(0.3); + } + if(y==0){ + key.putc(101); + wait(0.3); + } + } + + if((click<0.30)&&(click>0)){ - mouse.press(MOUSE_RIGHT); - else - mouse.release(MOUSE_RIGHT); + if(y>5){ + key.putc(99); + wait(0.3); + } + if(y==0){ + key.putc(102); + wait(0.3); + } + } + + wait(0.001);