Niranjan Ravi
/
FXOS8700Q_ACC_MAG_Display
Motion sensor program
main.cpp@2:a5a643b0eb25, 2019-09-18 (annotated)
- Committer:
- Niranjan_ravi
- Date:
- Wed Sep 18 00:38:49 2019 +0000
- Revision:
- 2:a5a643b0eb25
- Parent:
- 1:bdfa2e80230f
I2C-Acc-Mag
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Niranjan_ravi | 0:f665d23ec68a | 1 | #include "mbed.h" |
Niranjan_ravi | 0:f665d23ec68a | 2 | #include "FXOS8700Q.h" |
Niranjan_ravi | 0:f665d23ec68a | 3 | I2C i2c(PTE25, PTE24); |
Niranjan_ravi | 0:f665d23ec68a | 4 | Serial pc(USBTX,USBRX); |
Niranjan_ravi | 0:f665d23ec68a | 5 | FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Configured for the FRDM-K64F with onboard sensors |
Niranjan_ravi | 0:f665d23ec68a | 6 | FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1); |
Niranjan_ravi | 0:f665d23ec68a | 7 | int main(void) |
Niranjan_ravi | 0:f665d23ec68a | 8 | { |
Niranjan_ravi | 0:f665d23ec68a | 9 | motion_data_units_t acc_data, mag_data; |
Niranjan_ravi | 0:f665d23ec68a | 10 | motion_data_counts_t acc_raw, mag_raw; |
Niranjan_ravi | 0:f665d23ec68a | 11 | float faX, faY, faZ, fmX, fmY, fmZ, tmp_float; |
Niranjan_ravi | 0:f665d23ec68a | 12 | int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int; |
Niranjan_ravi | 0:f665d23ec68a | 13 | acc.enable(); |
Niranjan_ravi | 0:f665d23ec68a | 14 | mag.enable(); |
Niranjan_ravi | 0:f665d23ec68a | 15 | while (true) { |
Niranjan_ravi | 0:f665d23ec68a | 16 | // counts based results |
Niranjan_ravi | 0:f665d23ec68a | 17 | acc.getAxis(acc_raw); |
Niranjan_ravi | 0:f665d23ec68a | 18 | mag.getAxis(mag_raw); |
Niranjan_ravi | 0:f665d23ec68a | 19 | acc.getX(raX); |
Niranjan_ravi | 0:f665d23ec68a | 20 | acc.getY(raY); |
Niranjan_ravi | 0:f665d23ec68a | 21 | acc.getZ(raZ); |
Niranjan_ravi | 0:f665d23ec68a | 22 | mag.getX(rmX); |
Niranjan_ravi | 0:f665d23ec68a | 23 | mag.getY(rmY); |
Niranjan_ravi | 0:f665d23ec68a | 24 | mag.getZ(rmZ); |
Niranjan_ravi | 0:f665d23ec68a | 25 | // unit based results |
Niranjan_ravi | 0:f665d23ec68a | 26 | acc.getAxis(acc_data); |
Niranjan_ravi | 0:f665d23ec68a | 27 | mag.getAxis(mag_data); |
Niranjan_ravi | 0:f665d23ec68a | 28 | acc.getX(faX); |
Niranjan_ravi | 0:f665d23ec68a | 29 | acc.getY(faY); |
Niranjan_ravi | 0:f665d23ec68a | 30 | acc.getZ(faZ); |
Niranjan_ravi | 0:f665d23ec68a | 31 | mag.getX(fmX); |
Niranjan_ravi | 0:f665d23ec68a | 32 | mag.getY(fmY); |
Niranjan_ravi | 0:f665d23ec68a | 33 | mag.getZ(fmZ); |
Niranjan_ravi | 1:bdfa2e80230f | 34 | pc.printf("FXOSQ8700Q ACC: X=%1.4fY=%1.4fZ=%1.4f", acc.getX(faX),acc.getY(faY),acc.getZ(faZ)); |
Niranjan_ravi | 1:bdfa2e80230f | 35 | pc.printf(" MAG: X=%4.1fY=%4.1fZ=%4.1f\r\n", mag.getX(fmX),mag.getY(fmY), mag.getZ(fmZ)); |
Niranjan_ravi | 0:f665d23ec68a | 36 | wait(1.0f); |
Niranjan_ravi | 0:f665d23ec68a | 37 | } |
Niranjan_ravi | 0:f665d23ec68a | 38 | } |