Using a Touch Sensor
For this program you will need a robot with motors on ports A and C and a touch sensor on port 2.
The following program will move motors A and C forward at power level 1 until the touch sensor on port 2 is pressed. Then the motors will reverse at power level 5 for 1 second and then stop.

![]() |
|
Looping (Jump and Land)
When using a touch sensor, we want the robot to check more than once to see if the touch sensor has been pushed, otherwise it may be stuck against an object.
You can do this by putting loops into your program.
The following program will check 5 times to see if the touch sensor has been pushed, and if it has, it will turn for a random time up to 2 seconds.

If you want your program to continue running indefinitely, you can put an infinite loop in using Jump and Land icons. Jumps and Lands much be in pairs of matching colours.




Putting in a random Wait for, with a 2 second modifier will give
you a random time up to 2 seconds.