Mike Fedosiuk
/
FRDM_MMA8451Q
Good posture sensor
Fork of FRDM_MMA8451Q by
Revision 9:6bc7c9ece653, committed 2013-05-02
- Comitter:
- mfed1
- Date:
- Thu May 02 10:30:09 2013 +0000
- Parent:
- 8:704b1bb01b14
- Commit message:
- Chair sensor complete with led
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 704b1bb01b14 -r 6bc7c9ece653 main.cpp --- a/main.cpp Thu May 02 09:10:49 2013 +0000 +++ b/main.cpp Thu May 02 10:30:09 2013 +0000 @@ -2,6 +2,7 @@ #include "MMA8451Q.h" #define MMA8451_I2C_ADDRESS (0x1d<<1) +DigitalOut led(PTC12); int main(void) { MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); @@ -10,15 +11,27 @@ PwmOut bled(LED_BLUE); while (true) { - rled = 1.0 - abs(acc.getAccX()); + //rled = 1.0 - abs(acc.getAccX()); printf(" X "); - printf("%f",acc.getAccX()); - gled = 1.0 - abs(acc.getAccY()); + printf("%f",acc.getAccX()); //gives x coordinate of accelerometer + //gled = 1.0 - abs(acc.getAccY()); printf(" Y "); - printf("%f",acc.getAccY()); - bled = 1.0 - abs(acc.getAccZ()); + printf("%f",acc.getAccY()); //gives y coordinate of accelerometer + //bled = 1.0 - abs(acc.getAccZ()); printf(" Z "); - printf("%f\r",acc.getAccZ()); + printf("%f\r",acc.getAccZ()); //gives z coordinate of accelerometer + + if (acc.getAccZ()<-0.3){ //prints dont slouch + lights led when z axis less than -0.3 + printf("Don't Slouch"); + led=1; + } + else led=0; + + if (acc.getAccZ()>0.0){ //prints sit back = lights led when z axis more than 0 + printf("Sit Back"); + led=1; + } + wait(0.1); } }