SAMI NAQVI / Mbed OS TALab3C_i2c_acc

Dependencies:   FXAS21000 FXOS8700Q

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "FXOS8700Q.h"
00003     I2C i2c(PTE25, PTE24);
00004     Serial pc(USBTX,USBRX);
00005     FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1);    // Configured for the FRDM-K64F with onboard sensors
00006     FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1);
00007 
00008     int main(void)
00009     {
00010         motion_data_units_t acc_data, mag_data;
00011         motion_data_counts_t acc_raw, mag_raw;
00012         float faX, faY, faZ, fmX, fmY, fmZ, tmp_float;
00013         int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int;
00014         acc.enable();
00015         mag.enable();
00016         while (true) {
00017             // counts based results
00018             acc.getAxis(acc_raw);
00019             mag.getAxis(mag_raw);
00020             acc.getX(raX);
00021             acc.getY(raY);
00022             acc.getZ(raZ);
00023             mag.getX(rmX);
00024             mag.getY(rmY);
00025             mag.getZ(rmZ);
00026             // unit based results
00027             acc.getAxis(acc_data);
00028             mag.getAxis(mag_data);
00029             acc.getX(faX);
00030             acc.getY(faY);
00031             acc.getZ(faZ);
00032             mag.getX(fmX);
00033             mag.getY(fmY);
00034             mag.getZ(fmZ);
00035            pc.printf("FXOSQ8700Q ACC: X=%1.4fY=%1.4fZ=%1.4f", acc.getX(faX),acc.getY(faY),acc.getZ(faZ));
00036            pc.printf("      MAG: X=%4.1fY=%4.1fZ=%4.1f\r\n", mag.getX(fmX),mag.getY(fmY), mag.getZ(fmZ));
00037             wait(1.0f);
00038         }
00039     }