Anastasios Barlas
/
Accelerometer_example_Step2
Lab 4 Part 2
Fork of Accelerometer_example by
Diff: main.cpp
- Revision:
- 2:a5761fdb74f0
- Parent:
- 0:a1caba5c4e48
diff -r 31f0f53b08bd -r a5761fdb74f0 main.cpp --- a/main.cpp Wed Feb 07 16:56:55 2018 +0000 +++ b/main.cpp Fri Feb 16 22:01:18 2018 +0000 @@ -19,14 +19,38 @@ 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(); rled = 1.0f - abs(x); gled = 1.0f - abs(y); bled = 1.0f - abs(z); + 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 (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 (z<=t && abs(y) < t && abs(x) < t ){ + pc.printf("over"); + } + else if (z>=t && abs(y) < t && abs(x) < t ){ + pc.printf("flat"); + } + else{ + rled = 1; + gled = 1; + bled = 1; + } Thread::wait(300); - pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z); + //pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n \r", x, y, z); } }