César Fierro / Mbed 2 deprecated i2ctry

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers i2c.cpp Source File

i2c.cpp

00001 #include "mbed.h"
00002 #include "MMA8451Q.h"
00003 
00004   PinName const SDA = PTE25;
00005   PinName const SCL = PTE24;
00006   DigitalOut myled(LED2);
00007   
00008   #define MMA8451_I2C_ADDRESS (0x1d<<1)
00009 
00010 
00011 int main(){
00012     
00013 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
00014 
00015    while (true) {
00016         float x, y, z;
00017         x = abs(acc.getAccX());
00018         y = abs(acc.getAccY());
00019         z = abs(acc.getAccZ());
00020         
00021         if (x>0.5)
00022         {
00023             myled = 0;
00024         }
00025         else
00026         {
00027             myled = 1;
00028         }
00029         printf("%f",x);
00030     }
00031     
00032 }