I'm trying to run an error correction code for my mouse so it does not run into walls. I want the mouse to move forward one cell at a time (173 steps). But it detects right and left walls, I want it to correct itself. If it doesnt detect a wall on either or both sides, I want the mouse to simply move to the next cell. Im not a strong programmer so much help would be appreciated. The code for my move forward one cell is listed below:
void goStraightOneSquare()
{
int i = 0;
for (i=0; i<173; i++) {
rightmotor1.step(1, BACKWARD, DOUBLE);
leftmotor2.step(1, FORWARD, DOUBLE); //move foward 173 steps
if(analogRead(RightSensePin) < 1010 || analogRead(LeftSensePin) < 1010)
rightmotor1.step(1, BACKWARD, DOUBLE);
leftmotor2.step(1, FORWARD, DOUBLE);
if(1020 < analogRead(RightSensePin) < 1023) //if too far from right wall, left motor takes a step
leftmotor2.step(1, FORWARD, DOUBLE);
if(1020 < analogRead(LeftSensePin) <1023) //if too far from left wall, right motor takes a step
rightmotor1.step(1, BACKWARD, DOUBLE);
}
delay (250);