Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma config(Sensor, dgtl11, bumpy, sensorTouch)
- #pragma config(Motor, port2, rightMotor, tmotorServoContinuousRotation, openLoop, reversed)
- #pragma config(Motor, port3, leftMotor, tmotorServoContinuousRotation, openLoop)
- //below are functions to shorten my code
- //"backup" is the function. "backtime" is the variable.
- void backup(int backtime)
- {
- motor[rightMotor] = 0;
- motor[leftMotor] = 0;
- wait1Msec(200);
- motor[rightMotor] = -90;
- motor[leftMotor] = -90;
- wait1Msec(backtime);
- motor[rightMotor] = 0;
- motor[leftMotor] = 0;
- wait1Msec(200);
- }
- void leftturn(int turntime)
- {
- motor[rightMotor] = 0;
- motor[leftMotor] = 0;
- wait1Msec(200);
- motor[rightMotor] = 90;
- motor[leftMotor] = -90;
- wait1Msec(turntime);
- motor[rightMotor] = 0;
- motor[leftMotor] = 0;
- wait1Msec(200);
- }
- void rightturn(int turntime)
- {
- motor[rightMotor] = 0;
- motor[leftMotor] = 0;
- wait1Msec(200);
- motor[rightMotor] = -90;
- motor[leftMotor] = 90;
- wait1Msec(turntime);
- motor[rightMotor] = 0;
- motor[leftMotor] = 0;
- wait1Msec(200);
- }
- //+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
- //the functions are "called" by using the function name,
- //then the number inside () is the variable value.
- task main()
- {
- int counter = 0;
- while (true)
- {
- motor[rightMotor] = 127;
- motor[leftMotor] = 127;
- //counter is at 0
- if (SensorValue[bumpy] == 1)
- {counter++;} //counter increases by 1
- if(counter == 1)
- { backup(250);
- leftturn(270);
- counter++; //counter goes to 2
- }
- if(counter == 3)
- { backup(250);
- rightturn(270);
- counter = 0;
- }
- }
- }
Add Comment
Please, Sign In to add comment