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

Dependencies:   MMA8451Q TSI USBDevice mbed

Dependents:   Airmouse_

main.cpp

Committer:
Future_FThierry
Date:
2013-06-24
Revision:
0:a7df8e8cc00c

File content as of revision 0:a7df8e8cc00c:

#include "mbed.h"
#include "USBMouse.h"
#include "MMA8451Q.h"
#include "TSISensor.h"

#define MMA8451_I2C_ADDRESS (0x1d<<1)

USBMouse mouse;
Serial pc(USBTX, USBRX); // tx, rx

int main()
{
    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();

        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.30)&&(click>0))
            
            mouse.press(MOUSE_RIGHT);
            else
            mouse.release(MOUSE_RIGHT);
            
        wait(0.001);
       
    }
}