![](/media/cache/profiles/IvyS.JPG.50x50_q85.jpg)
state led / position change
Fork of Accelerometer_example by
Diff: main.cpp
- Revision:
- 3:ca2e99f6b193
- Parent:
- 2:18e28291bc02
- Child:
- 4:42e2706f9847
diff -r 18e28291bc02 -r ca2e99f6b193 main.cpp --- a/main.cpp Thu Feb 15 18:28:42 2018 +0000 +++ b/main.cpp Fri Feb 16 11:53:18 2018 +0000 @@ -23,24 +23,55 @@ x = acc.getAccX(); y = acc.getAccY(); z = acc.getAccZ(); - rled = 1.0f - abs(x); - gled = 1.0f - abs(y); - bled = 1.0f - abs(z); - Thread::wait(300); + + Thread::wait (300); - - - pc.printf("X:flat ,Y:right ,Z:left\n", x,y,z); + //Flat my led + if(z>= 0.9){ + + rled = 0; + gled = 0; + bled = 0; + + pc.printf("flat\n\r"); + + }else if (y>=0.9){ + + //right my led + rled = 0; + gled = 0; + bled = 0; + pc.printf("right\n\r"); + + }else if (x>=0.9){ + //over + + rled = 0; + gled = 0; + bled = 0; + pc.printf("over \n \r"); + + }else if (x<= -0.90){ + + rled = 0; + gled = 0; + bled = 0; + pc.printf("up\n\r"); + + } + + else { + + rled = 1; + gled = 1; + bled = 1; + pc.printf("\n\r"); + + } - // if (x> 0){ - - // pc.printf("X:flat ,Y:right ,Z:left\n", x,y,z); - - //} - //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); + }