![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
rev 1.0
Fork of FRDM-K64_AccelMag by
main.cpp@1:744ec0ebf949, 2017-12-06 (annotated)
- Committer:
- DamianSan
- Date:
- Wed Dec 06 13:29:49 2017 +0000
- Revision:
- 1:744ec0ebf949
- Parent:
- 0:90ba5c73bcfb
Final version of accelerometer example program for FRDM-K64F evaluation board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
APanecatl | 0:90ba5c73bcfb | 1 | #include "mbed.h" |
APanecatl | 0:90ba5c73bcfb | 2 | #include "FXOS8700Q.h" |
APanecatl | 0:90ba5c73bcfb | 3 | |
DamianSan | 1:744ec0ebf949 | 4 | //I2C line for FXOS8700Q accelerometer |
APanecatl | 0:90ba5c73bcfb | 5 | FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); |
DamianSan | 1:744ec0ebf949 | 6 | //I2C line for FXOS8700Q magnetometer |
APanecatl | 0:90ba5c73bcfb | 7 | FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); |
APanecatl | 0:90ba5c73bcfb | 8 | |
DamianSan | 1:744ec0ebf949 | 9 | //Terminal communication init. |
APanecatl | 0:90ba5c73bcfb | 10 | Serial pc(USBTX, USBRX); |
APanecatl | 0:90ba5c73bcfb | 11 | |
DamianSan | 1:744ec0ebf949 | 12 | //Accelerometer data variables |
DamianSan | 1:744ec0ebf949 | 13 | //MotionSensorDataUnits mag_data; |
DamianSan | 1:744ec0ebf949 | 14 | //MotionSensorDataUnits acc_data; |
APanecatl | 0:90ba5c73bcfb | 15 | |
APanecatl | 0:90ba5c73bcfb | 16 | |
APanecatl | 0:90ba5c73bcfb | 17 | int main() |
APanecatl | 0:90ba5c73bcfb | 18 | { |
DamianSan | 1:744ec0ebf949 | 19 | float accelX, accelY, accelZ; |
DamianSan | 1:744ec0ebf949 | 20 | float magnetoX, magnetoY, magnetoZ; |
DamianSan | 1:744ec0ebf949 | 21 | |
DamianSan | 1:744ec0ebf949 | 22 | //Enable Accelerometer |
APanecatl | 0:90ba5c73bcfb | 23 | acc.enable(); |
DamianSan | 1:744ec0ebf949 | 24 | printf("\r\n\nFXOS8700Q Address on I2C bus = %X\r\n", acc.whoAmI()); |
APanecatl | 0:90ba5c73bcfb | 25 | |
APanecatl | 0:90ba5c73bcfb | 26 | while (true) |
DamianSan | 1:744ec0ebf949 | 27 | { |
DamianSan | 1:744ec0ebf949 | 28 | /* GET AXIS VALUES FROM ACCELEROMETER AND MAGNETOMETER*/ |
DamianSan | 1:744ec0ebf949 | 29 | acc.getX(&accelX); |
DamianSan | 1:744ec0ebf949 | 30 | //acc.getY(&accelY); |
DamianSan | 1:744ec0ebf949 | 31 | //acc.getZ(&accelZ); |
DamianSan | 1:744ec0ebf949 | 32 | //mag.getX(&magnetoX); |
DamianSan | 1:744ec0ebf949 | 33 | //mag.getY(&magnetoY); |
DamianSan | 1:744ec0ebf949 | 34 | //mag.getZ(&magnetoZ); |
DamianSan | 1:744ec0ebf949 | 35 | /* SCALE AXIS VALUES TO DEGREES*/ |
DamianSan | 1:744ec0ebf949 | 36 | accelX *= 90; |
DamianSan | 1:744ec0ebf949 | 37 | //accelY *= 180; |
DamianSan | 1:744ec0ebf949 | 38 | //accelZ *= 180; |
DamianSan | 1:744ec0ebf949 | 39 | /* PRINT THOSE VALUES */ |
DamianSan | 1:744ec0ebf949 | 40 | //printf("FXOS8700Q ACC: X=%1.2f' Y=%1.2f' Z=%1.2f' ", accelX, accelY, accelZ); |
DamianSan | 1:744ec0ebf949 | 41 | //printf(" MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", magnetoX, magnetoY, magnetoZ); |
DamianSan | 1:744ec0ebf949 | 42 | printf("AccelX: %1.2f\n\r",accelX); |
DamianSan | 1:744ec0ebf949 | 43 | wait(1.0); //delay |
APanecatl | 0:90ba5c73bcfb | 44 | } |
APanecatl | 0:90ba5c73bcfb | 45 | } |