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

Dependencies:   mbed MMA8451Q

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MMA8451Q.h"
00003 #define MMA8451_I2C_ADDRESS (0x1D<<1)
00004 Serial pc(USBTX,USBRX);
00005 MMA8451Q acc(PTE25,PTE24,MMA8451_I2C_ADDRESS);
00006 BusOut myled(LED3,LED2,LED1);
00007 float x,y,z;
00008 int main()
00009 {
00010     while(1) 
00011     {
00012        x=acc.getAccX();
00013        y=acc.getAccY();
00014        z=acc.getAccZ();
00015        if((x<=0.2&&x>=-0.2)&&(y<=0.2&&y>=-0.2))
00016         {
00017             
00018             myled = 0x05;
00019            
00020         }
00021        else if((x>=0.5||x<=-0.5)||(y>=0.5||y<=-0.5))
00022         {
00023             myled = 0x03;
00024            
00025         } 
00026         else 
00027         {
00028             myled = 0x06;
00029             
00030         }
00031     }
00032 }