Test application for Freedom KL25Z, mouse driven by accelerometer and click with TSI interface

Dependencies:   MMA8451Q TSI USBDevice mbed

Fork of Airmouse by Frederic Thierry

Committer:
rod08018
Date:
Thu Jun 09 01:35:29 2016 +0000
Revision:
1:647d6636eb03
Parent:
0:a7df8e8cc00c
lab usb Universidad Galileo David rodriguez

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Future_FThierry 0:a7df8e8cc00c 1 #include "mbed.h"
Future_FThierry 0:a7df8e8cc00c 2 #include "USBMouse.h"
Future_FThierry 0:a7df8e8cc00c 3 #include "MMA8451Q.h"
Future_FThierry 0:a7df8e8cc00c 4 #include "TSISensor.h"
rod08018 1:647d6636eb03 5 #include "USBMouseKeyboard.h"
Future_FThierry 0:a7df8e8cc00c 6 #define MMA8451_I2C_ADDRESS (0x1d<<1)
rod08018 1:647d6636eb03 7 #include "USBKeyboard.h"
Future_FThierry 0:a7df8e8cc00c 8 USBMouse mouse;
Future_FThierry 0:a7df8e8cc00c 9 Serial pc(USBTX, USBRX); // tx, rx
rod08018 1:647d6636eb03 10 USBKeyboard key;
Future_FThierry 0:a7df8e8cc00c 11 int main()
Future_FThierry 0:a7df8e8cc00c 12 {
rod08018 1:647d6636eb03 13 //Debe cambiar su air mouse a un simple keyboard. Debe poder ingresar 3 teclas del teclado “a”, “b” y “c”.
rod08018 1:647d6636eb03 14 //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.
rod08018 1:647d6636eb03 15 //Puede utilizar su imaginación para mejorar la interfaz.
Future_FThierry 0:a7df8e8cc00c 16 float click =0;
Future_FThierry 0:a7df8e8cc00c 17 int16_t x = 0;
Future_FThierry 0:a7df8e8cc00c 18 int16_t y = 0;
Future_FThierry 0:a7df8e8cc00c 19 TSISensor tsi;
Future_FThierry 0:a7df8e8cc00c 20 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
rod08018 1:647d6636eb03 21
Future_FThierry 0:a7df8e8cc00c 22 while (1) {
Future_FThierry 0:a7df8e8cc00c 23 x = -10*acc.getAccY();
Future_FThierry 0:a7df8e8cc00c 24 y = 10*acc.getAccX();
rod08018 1:647d6636eb03 25 pc.printf("%f\n",x);
Future_FThierry 0:a7df8e8cc00c 26 mouse.move(x, y);
rod08018 1:647d6636eb03 27
Future_FThierry 0:a7df8e8cc00c 28 click=tsi.readPercentage();
Future_FThierry 0:a7df8e8cc00c 29 //pc.printf("%f\n",click);
rod08018 1:647d6636eb03 30 if (click>0.70){
rod08018 1:647d6636eb03 31 if(y>5){
rod08018 1:647d6636eb03 32 key.putc(97);
rod08018 1:647d6636eb03 33 wait(0.3);
rod08018 1:647d6636eb03 34 }
rod08018 1:647d6636eb03 35 if(y==0){
rod08018 1:647d6636eb03 36 key.putc(100);
rod08018 1:647d6636eb03 37 wait(0.3);
rod08018 1:647d6636eb03 38 }
rod08018 1:647d6636eb03 39 }
rod08018 1:647d6636eb03 40 if((click<0.60)&&(click>0.30)){
Future_FThierry 0:a7df8e8cc00c 41
rod08018 1:647d6636eb03 42 if(y>5){
rod08018 1:647d6636eb03 43 key.putc(98);
rod08018 1:647d6636eb03 44 wait(0.3);
rod08018 1:647d6636eb03 45 }
rod08018 1:647d6636eb03 46 if(y==0){
rod08018 1:647d6636eb03 47 key.putc(101);
rod08018 1:647d6636eb03 48 wait(0.3);
rod08018 1:647d6636eb03 49 }
rod08018 1:647d6636eb03 50 }
rod08018 1:647d6636eb03 51
rod08018 1:647d6636eb03 52 if((click<0.30)&&(click>0)){
Future_FThierry 0:a7df8e8cc00c 53
rod08018 1:647d6636eb03 54 if(y>5){
rod08018 1:647d6636eb03 55 key.putc(99);
rod08018 1:647d6636eb03 56 wait(0.3);
rod08018 1:647d6636eb03 57 }
rod08018 1:647d6636eb03 58 if(y==0){
rod08018 1:647d6636eb03 59 key.putc(102);
rod08018 1:647d6636eb03 60 wait(0.3);
rod08018 1:647d6636eb03 61 }
rod08018 1:647d6636eb03 62 }
rod08018 1:647d6636eb03 63
rod08018 1:647d6636eb03 64
Future_FThierry 0:a7df8e8cc00c 65
Future_FThierry 0:a7df8e8cc00c 66 wait(0.001);
Future_FThierry 0:a7df8e8cc00c 67
Future_FThierry 0:a7df8e8cc00c 68 }
Future_FThierry 0:a7df8e8cc00c 69 }