Machine Agricole

Dependencies:   FXOS8700Q mbed

Committer:
mfalhimohamed
Date:
Sun Feb 11 12:53:37 2018 +0000
Revision:
0:f87ac8b6fae4
CENTER 3D

Who changed what in which revision?

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