Jiajun Zhang
/
Accelerometer_example
Part 1 of lab 4
Fork of Accelerometer_example by
Revision 2:0ee311fae3ff, committed 2018-02-16
- Comitter:
- Bossman
- Date:
- Fri Feb 16 20:07:08 2018 +0000
- Parent:
- 1:31f0f53b08bd
- Commit message:
- Version 1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 31f0f53b08bd -r 0ee311fae3ff main.cpp --- a/main.cpp Wed Feb 07 16:56:55 2018 +0000 +++ b/main.cpp Fri Feb 16 20:07:08 2018 +0000 @@ -19,7 +19,8 @@ pc.printf("MMA8451 ID: %d\n", acc.getWhoAmI()); while (true) { - float x, y, z; + float x, y, z,t; + t=0.5; x = acc.getAccX(); y = acc.getAccY(); z = acc.getAccZ(); @@ -27,6 +28,23 @@ gled = 1.0f - abs(y); bled = 1.0f - abs(z); Thread::wait(300); - pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z); + if ((x<-t)&&(abs(y)<t)&&(abs(z)<t)){ + pc.printf("left"); + } + else if ((x>t)&&(abs(y)<t)&&(abs(z)<t)){ + pc.printf("right"); + } + else if ((y<-t)&&(abs(x)<t)&&(abs(z)<t)){ + pc.printf("down"); + } + else if ((y>t)&&(abs(x)<t)&&(abs(z)<t)){ + pc.printf("up"); + } + else if (z>t){ + pc.printf("flat"); + } + else if (z<-t){ + pc.printf("over"); + } } }