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
Revision 3:2a8e59a590db, committed 2014-03-05
- Comitter:
- ashleymills
- Date:
- Wed Mar 05 16:48:41 2014 +0000
- Parent:
- 2:0630128bdb32
- Child:
- 4:936b60956489
- Commit message:
- Updated child, cleaned something.
Changed in this revision
MMA8452.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MMA8452.lib Wed Mar 05 15:36:30 2014 +0000 +++ b/MMA8452.lib Wed Mar 05 16:48:41 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/ashleymills/code/MMA8452/#7620a11149b8 +http://mbed.org/users/ashleymills/code/MMA8452/#d6dde2318edc
--- a/main.cpp Wed Mar 05 15:36:30 2014 +0000 +++ b/main.cpp Wed Mar 05 16:48:41 2014 +0000 @@ -233,8 +233,6 @@ } int twosCompTest() { - u16d((int16_t)5); - u16d((int16_t)-5); // 12 bits of number gives 2048 steps int16_t i = -2047; while(1) {