tuxduino:
I spotted this:else if(distance <= CRITdistance) {
CRITvar = 1; // you assign a value
switch(CRITvar) { // then immediately test for its value
case 1 : // of course this case will always be selected
resetPREVangle();
prevmillis = millis();
while(millis() - prevmillis < 5000) {
walkBWD();
CRITvar = 2;
} // missing "break", so case 2: will also be executed
case 2 :
resetPREVangle();
ultrasoundSWITCH = 1;
stallVAR = 0;
turnRightVAR = 0;
turnLeftVAR = 0;
rotate();
break;
}
}
CRITVar is not used elsewhere, so the code can be simplified as follows:
else if(distance <= CRITdistance) {
resetPREVangle();
prevmillis = millis();
while(millis() - prevmillis < 5000) {
walkBWD();
}
resetPREVangle();
ultrasoundSWITCH = 1;
stallVAR = 0;
turnRightVAR = 0;
turnLeftVAR = 0;
rotate();
}
my 1 cent :-)
Awesome tuxduino!! And that's not 1 cent, that's a million for your kindness to help me!
But I need "switch" function to keep the robot rotate routine not interfere by CRITdistance value till it's rotate routine completed. You see, the robot rotate left then right (or right then left, randomly) to compare which direction has longest distance to walk by.
But it still just my argument, I need to prove it by implementing your suggestion.
So I'll try your revision first..
I'll report whether it works or not..