Gustavo Toribio
/
Accel_magnetometro
accel mag
Fork of Hello_FXOS8700Q_copy by
main.cpp@0:b766735d049d, 2015-12-18 (annotated)
- Committer:
- gtoribio
- Date:
- Fri Dec 18 20:09:50 2015 +0000
- Revision:
- 0:b766735d049d
accel;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gtoribio | 0:b766735d049d | 1 | |
gtoribio | 0:b766735d049d | 2 | |
gtoribio | 0:b766735d049d | 3 | #include "mbed.h" |
gtoribio | 0:b766735d049d | 4 | #include "FXOS8700Q.h" |
gtoribio | 0:b766735d049d | 5 | |
gtoribio | 0:b766735d049d | 6 | Serial pc(USBTX, USBRX); |
gtoribio | 0:b766735d049d | 7 | I2C i2c(PTE25, PTE24); |
gtoribio | 0:b766735d049d | 8 | //FXOS8700Q fxos(i2c, FXOS8700CQ_SLAVE_ADDR1); |
gtoribio | 0:b766735d049d | 9 | FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Configured for the FRDM-K64F with onboard sensors |
gtoribio | 0:b766735d049d | 10 | FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1); |
gtoribio | 0:b766735d049d | 11 | //FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR0); // Configured for use with the FRDM-MULTI shield |
gtoribio | 0:b766735d049d | 12 | //FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR0); |
gtoribio | 0:b766735d049d | 13 | |
gtoribio | 0:b766735d049d | 14 | |
gtoribio | 0:b766735d049d | 15 | int main(void) |
gtoribio | 0:b766735d049d | 16 | { |
gtoribio | 0:b766735d049d | 17 | motion_data_units_t acc_data, mag_data; |
gtoribio | 0:b766735d049d | 18 | motion_data_counts_t acc_raw, mag_raw; |
gtoribio | 0:b766735d049d | 19 | float faX, faY, faZ, fmX, fmY, fmZ, tmp_float; |
gtoribio | 0:b766735d049d | 20 | int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int; |
gtoribio | 0:b766735d049d | 21 | |
gtoribio | 0:b766735d049d | 22 | acc.enable(); |
gtoribio | 0:b766735d049d | 23 | mag.enable(); |
gtoribio | 0:b766735d049d | 24 | printf("FXOS8700QAccelerometro = %X\r\n", acc.whoAmI()); |
gtoribio | 0:b766735d049d | 25 | printf("FXOS8700QMagnetometro = %X\r\n", acc.whoAmI()); |
gtoribio | 0:b766735d049d | 26 | while (true) { |
gtoribio | 0:b766735d049d | 27 | |
gtoribio | 0:b766735d049d | 28 | acc.getAxis(acc_raw); |
gtoribio | 0:b766735d049d | 29 | mag.getAxis(mag_raw); |
gtoribio | 0:b766735d049d | 30 | printf("ACC: X=%06dd Y=%06dd Z=%06dd \t MAG: X=%06dd Y=%06dd Z=%06dd\r\n", acc_raw.x, acc_raw.y, acc_raw.z, mag_raw.x, mag_raw.y, mag_raw.z); |
gtoribio | 0:b766735d049d | 31 | acc.getX(raX); |
gtoribio | 0:b766735d049d | 32 | acc.getY(raY); |
gtoribio | 0:b766735d049d | 33 | acc.getZ(raZ); |
gtoribio | 0:b766735d049d | 34 | mag.getX(rmX); |
gtoribio | 0:b766735d049d | 35 | mag.getY(rmY); |
gtoribio | 0:b766735d049d | 36 | mag.getZ(rmZ); |
gtoribio | 0:b766735d049d | 37 | printf("ACC: X=%06dd Y=%06dd Z=%06dd \t MAG: X=%06dd Y=%06dd Z=%06dd\r\n", raX, raY, raZ, rmX, rmY, rmZ); |
gtoribio | 0:b766735d049d | 38 | printf("ACC: X=%06dd Y=%06dd Z=%06dd \t MAG: X=%06dd Y=%06dd Z=%06dd\r\n", acc.getX(tmp_int), acc.getY(tmp_int), acc.getZ(tmp_int), mag.getX(tmp_int), mag.getY(tmp_int), mag.getZ(tmp_int)); |
gtoribio | 0:b766735d049d | 39 | |
gtoribio | 0:b766735d049d | 40 | acc.getAxis(acc_data); |
gtoribio | 0:b766735d049d | 41 | mag.getAxis(mag_data); |
gtoribio | 0:b766735d049d | 42 | printf("ACC: X=%1.4ff Y=%1.4ff Z=%1.4ff \t MAG: X=%4.1ff Y=%4.1ff Z=%4.1ff\r\n", acc_data.x, acc_data.y, acc_data.z, mag_data.x, mag_data.y, mag_data.z); |
gtoribio | 0:b766735d049d | 43 | acc.getX(faX); |
gtoribio | 0:b766735d049d | 44 | acc.getY(faY); |
gtoribio | 0:b766735d049d | 45 | acc.getZ(faZ); |
gtoribio | 0:b766735d049d | 46 | mag.getX(fmX); |
gtoribio | 0:b766735d049d | 47 | mag.getY(fmY); |
gtoribio | 0:b766735d049d | 48 | mag.getZ(fmZ); |
gtoribio | 0:b766735d049d | 49 | printf("ACC: X=%1.4ff Y=%1.4ff Z=%1.4ff \t MAG: X=%4.1ff Y=%4.1ff Z=%4.1ff\r\n", faX, faY, faZ, fmX, fmY, fmZ); |
gtoribio | 0:b766735d049d | 50 | printf("ACC: X=%1.4ff Y=%1.4ff Z=%1.4ff \t MAG: X=%4.1ff Y=%4.1ff Z=%4.1ff\r\n", acc.getX(tmp_float), acc.getY(tmp_float), acc.getZ(tmp_float), mag.getX(tmp_float), mag.getY(tmp_float), mag.getZ(tmp_float)); |
gtoribio | 0:b766735d049d | 51 | puts(""); |
gtoribio | 0:b766735d049d | 52 | //wait(5.0f); |
gtoribio | 0:b766735d049d | 53 | } |
gtoribio | 0:b766735d049d | 54 | } |