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.
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’