David Rodriguez Douglas Gonzalez

Dependencies:   MMA8451Q TSI USBDevice WakeUp mbed

Fork of labusb by Douglas Gonzalez

main.cpp

Committer:
dglmgc
Date:
2016-06-09
Revision:
1:2bdcfc75ee32
Parent:
0:a7df8e8cc00c
Child:
2:da744dca7faf

File content as of revision 1:2bdcfc75ee32:

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

#define MMA8451_I2C_ADDRESS (0x1d<<1)

USBKeyboard teclado;
Serial pc(USBTX, USBRX); // tx, rx

int main()
{
    float click =0;
    float clickant = 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();
    
        click=tsi.readPercentage();
        //pc.printf("%f\n",click);
        if(click < (clickant - 0.10) || click > (clickant + 0.10)) {
            if(x>0 && y > 0){                
                if (click>0.80)
                    teclado._putc(99);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(97);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(98);
            }
            if(x<0 && y > 0){                
                if (click>0.80)
                    teclado._putc(102);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(100);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(101);
            }
            if(x<0 && y < 0){                
                if (click>0.80)
                    teclado._putc(105);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(103);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(104);
            }
            if(x>0 && y < 0){                
                if (click>0.80)
                    teclado._putc(108);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(106);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(107);
            }
            if(x==0 && y < 0){                
                if (click>0.80)
                    teclado._putc(111);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(109);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(110);
            }
            if(x==0 && y > 0){                
                if (click>0.80)
                    teclado._putc(114);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(112);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(113);
            }
            if(x==0 && y == 0){                
                if (click>0.80)
                    teclado._putc(117);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(115);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(116);
            }
            if(x>0 && y == 0){                
                if (click>0.80)
                    teclado._putc(120);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(118);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(119);
            }
            if(x<0 && y == 0){                
                if (click>0.80)
                    teclado._putc(123);
                    
                if((click<0.30)&&(click>0))
                    teclado._putc(121);
                    
                if((click<0.80)&&(click>0.30))
                    teclado._putc(122);
            }
        }
        
        wait(0.001);
        clickant = click;
       
    }
}