embed Grove 3-Axis Digital Accelerometer
Fork of TestCode_MMA7660FC by
Revision 3:3c1ca823b659, committed 2015-02-04
- Comitter:
- s890506
- Date:
- Wed Feb 04 04:54:16 2015 +0000
- Parent:
- 2:152191e37eb1
- Commit message:
- init
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 152191e37eb1 -r 3c1ca823b659 main.cpp --- a/main.cpp Thu Jul 05 17:48:44 2012 +0000 +++ b/main.cpp Wed Feb 04 04:54:16 2015 +0000 @@ -4,6 +4,11 @@ #include "mbed.h" #include "MMA7660FC.h" +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + #define ADDR_MMA7660 0x98 // I2C SLAVE ADDR MMA7660FC MMA7660FC Acc(p28, p27, ADDR_MMA7660); //sda, scl, Addr @@ -24,7 +29,9 @@ while(1) { + myled4=1; float x=0, y=0, z=0; + float ax=0, ay=0, az=0; Acc.read_Tilt(&x, &y, &z); // Read the acceleration pc.printf("Tilt x: %2.2f degree \n", x); // Print the tilt orientation of the X axis @@ -37,7 +44,28 @@ pc.printf("y: %1.3f g \n", G_VALUE[Acc.read_y()]); // Print the Y axis acceleration pc.printf("z: %1.3f g \n", G_VALUE[Acc.read_z()]); // Print the Z axis acceleration pc.printf("\n"); - wait(5); + + ax = G_VALUE[Acc.read_x()]; + ay = G_VALUE[Acc.read_y()]; + az = G_VALUE[Acc.read_z()]; + + if(ax<0){ + myled1=1; + }else{ + myled1=0; + } + if(ay<0){ + myled2=1; + }else{ + myled2=0; + } + if(az<0){ + myled3=1; + }else{ + myled3=0; + } + + wait(1); } }