According to the input from the touch sensor, LEDs colour will change

Dependencies:   mbed MMA8451Q

main.cpp

Committer:
div1104
Date:
2021-01-23
Revision:
0:15df611f3004

File content as of revision 0:15df611f3004:

#include "mbed.h"
#include "MMA8451Q.h"
#define MMA8451_I2C_ADDRESS (0x1D<<1)
Serial pc(USBTX,USBRX);
MMA8451Q acc(PTE25,PTE24,MMA8451_I2C_ADDRESS);
BusOut myled(LED3,LED2,LED1);
float x,y,z;
int main()
{
    while(1) 
    {
       x=acc.getAccX();
       y=acc.getAccY();
       z=acc.getAccZ();
       if((x<=0.2&&x>=-0.2)&&(y<=0.2&&y>=-0.2))
        {
            
            myled = 0x05;
           
        }
       else if((x>=0.5||x<=-0.5)||(y>=0.5||y<=-0.5))
        {
            myled = 0x03;
           
        } 
        else 
        {
            myled = 0x06;
            
        }
    }
}