![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
rev 1.0
Fork of FRDM-K64_AccelMag by
main.cpp@0:90ba5c73bcfb, 2014-07-09 (annotated)
- Committer:
- APanecatl
- Date:
- Wed Jul 09 19:28:51 2014 +0000
- Revision:
- 0:90ba5c73bcfb
- Child:
- 1:744ec0ebf949
FRDM-K64 Accelerometer-Magnetometer demo
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 | |
APanecatl | 0:90ba5c73bcfb | 4 | //I2C lines for FXOS8700Q accelerometer/magnetometer |
APanecatl | 0:90ba5c73bcfb | 5 | FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); |
APanecatl | 0:90ba5c73bcfb | 6 | FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); |
APanecatl | 0:90ba5c73bcfb | 7 | |
APanecatl | 0:90ba5c73bcfb | 8 | //Temrinal enable |
APanecatl | 0:90ba5c73bcfb | 9 | Serial pc(USBTX, USBRX); |
APanecatl | 0:90ba5c73bcfb | 10 | |
APanecatl | 0:90ba5c73bcfb | 11 | MotionSensorDataUnits mag_data; |
APanecatl | 0:90ba5c73bcfb | 12 | MotionSensorDataUnits acc_data; |
APanecatl | 0:90ba5c73bcfb | 13 | |
APanecatl | 0:90ba5c73bcfb | 14 | |
APanecatl | 0:90ba5c73bcfb | 15 | int main() |
APanecatl | 0:90ba5c73bcfb | 16 | { |
APanecatl | 0:90ba5c73bcfb | 17 | float faX, faY, faZ; |
APanecatl | 0:90ba5c73bcfb | 18 | float fmX, fmY, fmZ; |
APanecatl | 0:90ba5c73bcfb | 19 | |
APanecatl | 0:90ba5c73bcfb | 20 | acc.enable(); |
APanecatl | 0:90ba5c73bcfb | 21 | printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI()); |
APanecatl | 0:90ba5c73bcfb | 22 | |
APanecatl | 0:90ba5c73bcfb | 23 | while (true) |
APanecatl | 0:90ba5c73bcfb | 24 | { |
APanecatl | 0:90ba5c73bcfb | 25 | acc.getAxis(acc_data); |
APanecatl | 0:90ba5c73bcfb | 26 | mag.getAxis(mag_data); |
APanecatl | 0:90ba5c73bcfb | 27 | printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f ", acc_data.x, acc_data.y, acc_data.z); |
APanecatl | 0:90ba5c73bcfb | 28 | printf(" MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z); |
APanecatl | 0:90ba5c73bcfb | 29 | acc.getX(&faX); |
APanecatl | 0:90ba5c73bcfb | 30 | acc.getY(&faY); |
APanecatl | 0:90ba5c73bcfb | 31 | acc.getZ(&faZ); |
APanecatl | 0:90ba5c73bcfb | 32 | mag.getX(&fmX); |
APanecatl | 0:90ba5c73bcfb | 33 | mag.getY(&fmY); |
APanecatl | 0:90ba5c73bcfb | 34 | mag.getZ(&fmZ); |
APanecatl | 0:90ba5c73bcfb | 35 | printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f ", faX, faY, faZ); |
APanecatl | 0:90ba5c73bcfb | 36 | printf(" MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", fmX, fmY, fmZ); |
APanecatl | 0:90ba5c73bcfb | 37 | |
APanecatl | 0:90ba5c73bcfb | 38 | wait(1.0); |
APanecatl | 0:90ba5c73bcfb | 39 | } |
APanecatl | 0:90ba5c73bcfb | 40 | } |