Need help on how to reverse motors

My robot has ir sensors around the out side of him. I want to make it so that when the ir sensor is triped the motors will reverse perminitly. I know how to make it so when the ir sensor is triped the motors reverse but after my robot moves away from the object the robot starts going forward again.

So imagian my robot moving foward then it detects an object then I want it to moved backwards untill the back sensor is triped.

Thanks

Hi paradox_qu,

You need to change your code to a kind of ‘latching’ logic like so:

START:

Drive motor forwards or backwards (Your choice)

LOOP:

If front sensor ‘tripped’ then reverse motor

If back sensor ‘tripped’ then forward motor

Goto LOOP

The code is looping and waiting for either sensor to ‘trip’ and then when it does trip, the appropriate ‘permanent’ action will be taken untill the next ‘trip’

Cheers ADI

Thanks you very much ADI i think I figured out how to do it. Now I gotta go home and try it.