//PROGRAM # 2
//BUMP A LOT----
'Tankbot' design p.83. 1 touch sensor with the bumper of your choice. Robot
backs up and turns right when it hits //something. Uses two tasks (main &
bump)
// sensors- Calls
the sensor at port 2 “BUMP”
#define BUMP SENSOR_2
// motors- Calls
the motors “LEFT” & “RIGHT”
#define LEFT OUT_A
#define RIGHT OUT_C
// other
constants
#define
TURN_TIME 150 //1 1/2 second
#define REV_TIME 50 // 1/2 second
task main()
{
// configure sensor- Tells the RCX that
the sensor at port 2 (BUMP) is a
//touch sensor
SetSensor(BUMP, SENSOR_TOUCH);
//Robot moves forward
On(LEFT+RIGHT); //turns LEFT & RIGHT motor on
// begin task called “bump”
start bump;
}//main
//this task has
the robot back up, turn right, and move forward if the touch
//sensor is
pressed
task bump()
{
while(true) //’while’ statement necessary or the robot will
perform task
//only ONE time
{
until(BUMP==1); //BUMP sensor =1 when pressed
// back up
Rev(LEFT+RIGHT);
Wait(REV_TIME);
// spin around
Fwd(LEFT);
Wait(TURN_TIME);
// resume
Fwd(RIGHT);
}
}