Code: #pragma config(ProgramType, NonCompetition) #pragma config(Sensor, in1, Ultrasonic, sensorSONAR, int1) #pragma config(Sensor, in3, backside, sensorSONAR, int2) #pragma config(Sensor, in5, touchSensor, sensorTouch) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() { int speed = 225; //bMotorReflected[port2]=true; //bMotorReflected[port3]=true; while(true) { if(SensorValue(Ultrasonic) > 8) {
motor[port1] = -speed; motor[port2] = -speed; } else { bool back = (SensorValue[backside]<8); motor[port1] =speed; motor[port2] =-speed; Sleep(1660); bool right = (SensorValue[backside]>8); bool left = (SensorValue[Ultrasonic]>8); motor[port1] =-speed; motor[port2] =speed; Sleep(1660); if(right) { motor[port1] = speed; motor[port2] = speed; Sleep(2500); motor[port1] = -speed; motor[port2] = 0; Sleep(2600); } else if(left) { motor[port1] = speed; motor[port2] = speed; Sleep(2500); motor[port1] = 0; motor[port2] = -speed; Sleep(2600); } else if(back) { StopAllTasks(); } else { motor[port1] =-speed; motor[port2] =speed; Sleep(3320); StopAllTasks(); } } if(SensorValue[touchSensor]!=0) { StopAllTasks(); } StopAllTasks(); } } |