The main.cpp program below demonstrates a simple way to interface with the MMA8452 accelerometer. The function reads in the acceleration data in the X, Y, and Z directions and displays them through a serial com port on a PC. The Putty Output figure below shows the output of the accelerometer using Putty. The program also dims or brightens the mbed LEDs 1-3 based on whether or not they are at 'level'( 0 Gs) or above respectively. The video below previews the code in action.
Fork of MMA8452_Test by
Diff: main.cpp
- Revision:
- 2:0630128bdb32
- Parent:
- 1:e9981919b524
- Child:
- 3:2a8e59a590db
--- a/main.cpp Wed Mar 05 15:04:45 2014 +0000 +++ b/main.cpp Wed Mar 05 15:36:30 2014 +0000 @@ -162,7 +162,9 @@ sampleMMA8452Counts(&acc,100); LOG("Samping gravities"); - sampleMMA8452Gravities(&acc,100); + acc.setBitDepth(MMA8452::BIT_DEPTH_8); + acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G); + sampleMMA8452Gravities(&acc,2000); return true; }