Program using Touch plane and accelerometer of FRDM-KL25Z board

Dependencies:   MMA8451Q TSI mbed

Fork of FRDM_TSI by mbed official

main.cpp

Committer:
subhrajitmitra
Date:
2013-04-22
Revision:
5:7f7b888f616b
Parent:
1:51b1b688179a

File content as of revision 5:7f7b888f616b:

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

#define MMA8451_I2C_ADDRESS (0x1d<<1)

int main(void) {
    MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
    
    PwmOut led1(LED_BLUE);
    PwmOut led2(LED_GREEN);
    PwmOut led3(LED_RED);
    
    float tp=0;
    
    TSISensor tsi;
   
    led1 = 1;
    led2 = 1;
    led3 = 1;
    
    while (1) 
    {   
        tp  = (tsi.readPercentage()>0)?tsi.readPercentage():tp;
          led1 = (tsi.readPercentage()==0)?(1-abs(acc.getAccX())):((tp>0.00 && tp <= 0.33)?(1-(tp-0.00)*3):1);
          led2 = (tsi.readPercentage()==0)?(1-abs(acc.getAccY())):((tp>=0.34 && tp <= 0.66)?(1-(tp-0.33)*3):1);
          led3 = (tsi.readPercentage()==0)?(1-abs(acc.getAccZ())):((tp>=0.67 && tp <= 0.99)?(1-(tp-0.66)*3):1);
          wait(0.1);
    }
}