nagaraju malla reddy palle
/
Hello_FXOS8700Q
Accelerator/magnetometer based toy car control using FRDM k64F
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* FXOS8700Q Example Program 00002 * Copyright (c) 2014-2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include "FXOS8700Q.h" 00019 00020 Serial pc(USBTX, USBRX); 00021 I2C i2c(PTE25, PTE24); 00022 //FXOS8700Q fxos(i2c, FXOS8700CQ_SLAVE_ADDR1); 00023 FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Configured for the FRDM-K64F with onboard sensors 00024 FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1); 00025 //FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR0); // Configured for use with the FRDM-MULTI shield 00026 //FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR0); 00027 00028 00029 int main(void) 00030 { 00031 motion_data_units_t acc_data, mag_data; 00032 motion_data_counts_t acc_raw, mag_raw; 00033 float faX, faY, faZ, fmX, fmY, fmZ, tmp_float; 00034 int16_t raX, raY, raZ, rmX, rmY, rmZ, tmp_int; 00035 00036 acc.enable(); 00037 mag.enable(); 00038 printf("FXOS8700QAccelerometer Who Am I= %X\r\n", acc.whoAmI()); 00039 printf("FXOS8700QMagnetometer Who Am I= %X\r\n", acc.whoAmI()); 00040 while (true) { 00041 // counts based results 00042 acc.getAxis(acc_raw); 00043 mag.getAxis(mag_raw); 00044 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); 00045 acc.getX(raX); 00046 acc.getY(raY); 00047 acc.getZ(raZ); 00048 mag.getX(rmX); 00049 mag.getY(rmY); 00050 mag.getZ(rmZ); 00051 printf("ACC: X=%06dd Y=%06dd Z=%06dd \t MAG: X=%06dd Y=%06dd Z=%06dd\r\n", raX, raY, raZ, rmX, rmY, rmZ); 00052 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)); 00053 // unit based results 00054 acc.getAxis(acc_data); 00055 mag.getAxis(mag_data); 00056 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); 00057 acc.getX(faX); 00058 acc.getY(faY); 00059 acc.getZ(faZ); 00060 mag.getX(fmX); 00061 mag.getY(fmY); 00062 mag.getZ(fmZ); 00063 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); 00064 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)); 00065 puts(""); 00066 wait(5.0f); 00067 } 00068 }
Generated on Wed Jul 13 2022 15:49:11 by 1.7.2