Controller for snake
Dependencies: MMA8451Q TSI mbed
Fork of foodcontroller3 by
Diff: main.cpp
- Revision:
- 3:768cca7d53fe
- Parent:
- 2:a6db66722be0
- Child:
- 4:1961b60aa8fb
--- a/main.cpp Thu Jun 09 09:37:00 2016 +0000 +++ b/main.cpp Thu Jun 09 10:22:08 2016 +0000 @@ -30,7 +30,11 @@ { while (1) { - if (tsi.readDistance() != 0) + + float accX=acc.getAccX(); //Measure acceleration in X direction + float accY=acc.getAccY(); //Measure acceleration in Y direction + + if (tsi.readDistance() != 0) { // gled = 1.0 - tsi.readPercentage(); if (tsi.readDistance() <= 13) @@ -50,11 +54,12 @@ wait(0.2); - }//endif touch sensor -/* + }//endif touch sensor + + if((accX <= 0.1f) && (accX >= -0.1f)) { - if (right == true) + if (right == false) { righthigh = 1; rightlow = 0; @@ -65,7 +70,7 @@ leftlow = 0; }//endelse }//endif - + if (accX > 0.1) { lefthigh = 0; @@ -76,7 +81,8 @@ forwardlow = 0; backwardhigh = 0; backwardlow = 0; - right = true; + right = false; + printf("left \r\n"); }//endif if (accX < -0.1) @@ -89,13 +95,14 @@ forwardlow = 0; backwardhigh = 0; backwardlow = 0; - right = false; + right = true; + printf("right \r\n"); }//endif - wait(0.1); + wait(0.1); - if((acc.getAccY() <= 0.1) && (acc.getAccY() >= -0.1)) + if((accY <= 0.1) && (accY >= -0.1)) { - if (forward == true) + if (forward == false) { forwardhigh = 1; forwardlow = 0; @@ -107,7 +114,7 @@ }//endelse }//endif - if (acc.getAccY() > 0.1) + if (accY > 0.1) { lefthigh = 0; leftlow = 0; @@ -117,10 +124,11 @@ forwardlow = 0; backwardhigh = 0; backwardlow = 0; - forward = true; + forward = false; + printf("back \r\n"); }//endif - if (acc.getAccY() < -0.1) + if (accY < -0.1) { lefthigh = 0; leftlow = 0; @@ -130,8 +138,18 @@ forwardlow = 0; backwardhigh = 1; backwardlow = 0; - forward = false; + forward = true; + printf("for \r\n"); }//endif - wait(0.1);*/ + + wait(0.1); + + /*if(abs(accY) > abs(accX)) + { + if(forward == e) + { + + } + }*/ }//endwhile }//endmain