![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test first
Dependencies: mbed SDFileSystem EthernetInterface FXOS8700Q
main.cpp@0:4536429d93c3, 2019-10-11 (annotated)
- Committer:
- navneet27
- Date:
- Fri Oct 11 05:54:56 2019 +0000
- Revision:
- 0:4536429d93c3
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
navneet27 | 0:4536429d93c3 | 1 | /* FXOS8700Q Example Program |
navneet27 | 0:4536429d93c3 | 2 | * Copyright (c) 2014-2015 ARM Limited |
navneet27 | 0:4536429d93c3 | 3 | * |
navneet27 | 0:4536429d93c3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
navneet27 | 0:4536429d93c3 | 5 | * you may not use this file except in compliance with the License. |
navneet27 | 0:4536429d93c3 | 6 | * You may obtain a copy of the License at |
navneet27 | 0:4536429d93c3 | 7 | * |
navneet27 | 0:4536429d93c3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
navneet27 | 0:4536429d93c3 | 9 | * |
navneet27 | 0:4536429d93c3 | 10 | * Unless required by applicable law or agreed to in writing, software |
navneet27 | 0:4536429d93c3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
navneet27 | 0:4536429d93c3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
navneet27 | 0:4536429d93c3 | 13 | * See the License for the specific language governing permissions and |
navneet27 | 0:4536429d93c3 | 14 | * limitations under the License. |
navneet27 | 0:4536429d93c3 | 15 | */ |
navneet27 | 0:4536429d93c3 | 16 | |
navneet27 | 0:4536429d93c3 | 17 | #include "mbed.h" |
navneet27 | 0:4536429d93c3 | 18 | #include "FXOS8700Q.h" |
navneet27 | 0:4536429d93c3 | 19 | |
navneet27 | 0:4536429d93c3 | 20 | Serial pc(USBTX, USBRX); |
navneet27 | 0:4536429d93c3 | 21 | I2C i2c(PTE25, PTE24); |
navneet27 | 0:4536429d93c3 | 22 | //FXOS8700Q fxos(i2c, FXOS8700CQ_SLAVE_ADDR1); |
navneet27 | 0:4536429d93c3 | 23 | FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Configured for the FRDM-K64F with onboard sensors |
navneet27 | 0:4536429d93c3 | 24 | FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1); |
navneet27 | 0:4536429d93c3 | 25 | //FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR0); // Configured for use with the FRDM-MULTI shield |
navneet27 | 0:4536429d93c3 | 26 | //FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR0); |
navneet27 | 0:4536429d93c3 | 27 | |
navneet27 | 0:4536429d93c3 | 28 | |
navneet27 | 0:4536429d93c3 | 29 | int main(void) |
navneet27 | 0:4536429d93c3 | 30 | { |
navneet27 | 0:4536429d93c3 | 31 | motion_data_units_t acc_data, mag_data; |
navneet27 | 0:4536429d93c3 | 32 | motion_data_counts_t acc_raw, mag_raw; |
navneet27 | 0:4536429d93c3 | 33 | float faX, faY, faZ, fmX, fmY, fmZ, tmp_float; |
navneet27 | 0:4536429d93c3 | 34 | int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int; |
navneet27 | 0:4536429d93c3 | 35 | |
navneet27 | 0:4536429d93c3 | 36 | acc.enable(); |
navneet27 | 0:4536429d93c3 | 37 | mag.enable(); |
navneet27 | 0:4536429d93c3 | 38 | printf("FXOS8700QAccelerometer Who Am I= %X\r\n", acc.whoAmI()); |
navneet27 | 0:4536429d93c3 | 39 | printf("FXOS8700QMagnetometer Who Am I= %X\r\n", acc.whoAmI()); |
navneet27 | 0:4536429d93c3 | 40 | while (true) { |
navneet27 | 0:4536429d93c3 | 41 | // counts based results |
navneet27 | 0:4536429d93c3 | 42 | acc.getAxis(acc_raw); |
navneet27 | 0:4536429d93c3 | 43 | mag.getAxis(mag_raw); |
navneet27 | 0:4536429d93c3 | 44 | 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); |
navneet27 | 0:4536429d93c3 | 45 | acc.getX(raX); |
navneet27 | 0:4536429d93c3 | 46 | acc.getY(raY); |
navneet27 | 0:4536429d93c3 | 47 | acc.getZ(raZ); |
navneet27 | 0:4536429d93c3 | 48 | mag.getX(rmX); |
navneet27 | 0:4536429d93c3 | 49 | mag.getY(rmY); |
navneet27 | 0:4536429d93c3 | 50 | mag.getZ(rmZ); |
navneet27 | 0:4536429d93c3 | 51 | printf("ACC: X=%06dd Y=%06dd Z=%06dd \t MAG: X=%06dd Y=%06dd Z=%06dd\r\n", raX, raY, raZ, rmX, rmY, rmZ); |
navneet27 | 0:4536429d93c3 | 52 | 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)); |
navneet27 | 0:4536429d93c3 | 53 | // unit based results |
navneet27 | 0:4536429d93c3 | 54 | acc.getAxis(acc_data); |
navneet27 | 0:4536429d93c3 | 55 | mag.getAxis(mag_data); |
navneet27 | 0:4536429d93c3 | 56 | 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); |
navneet27 | 0:4536429d93c3 | 57 | acc.getX(faX); |
navneet27 | 0:4536429d93c3 | 58 | acc.getY(faY); |
navneet27 | 0:4536429d93c3 | 59 | acc.getZ(faZ); |
navneet27 | 0:4536429d93c3 | 60 | mag.getX(fmX); |
navneet27 | 0:4536429d93c3 | 61 | mag.getY(fmY); |
navneet27 | 0:4536429d93c3 | 62 | mag.getZ(fmZ); |
navneet27 | 0:4536429d93c3 | 63 | 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); |
navneet27 | 0:4536429d93c3 | 64 | 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)); |
navneet27 | 0:4536429d93c3 | 65 | puts(""); |
navneet27 | 0:4536429d93c3 | 66 | wait(5.0f); |
navneet27 | 0:4536429d93c3 | 67 | } |
navneet27 | 0:4536429d93c3 | 68 | } |