Guest User

Untitled

a guest
Feb 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #pragma config(Sensor, dgtl11, bumpy, sensorTouch)
  2. #pragma config(Motor, port2, rightMotor, tmotorServoContinuousRotation, openLoop, reversed)
  3. #pragma config(Motor, port3, leftMotor, tmotorServoContinuousRotation, openLoop)
  4.  
  5. //below are functions to shorten my code
  6. //"backup" is the function. "backtime" is the variable.
  7. void backup(int backtime)
  8. {
  9. motor[rightMotor] = 0;
  10. motor[leftMotor] = 0;
  11. wait1Msec(200);
  12. motor[rightMotor] = -90;
  13. motor[leftMotor] = -90;
  14. wait1Msec(backtime);
  15. motor[rightMotor] = 0;
  16. motor[leftMotor] = 0;
  17. wait1Msec(200);
  18. }
  19.  
  20. void leftturn(int turntime)
  21. {
  22. motor[rightMotor] = 0;
  23. motor[leftMotor] = 0;
  24. wait1Msec(200);
  25. motor[rightMotor] = 90;
  26. motor[leftMotor] = -90;
  27. wait1Msec(turntime);
  28. motor[rightMotor] = 0;
  29. motor[leftMotor] = 0;
  30. wait1Msec(200);
  31. }
  32.  
  33. void rightturn(int turntime)
  34. {
  35. motor[rightMotor] = 0;
  36. motor[leftMotor] = 0;
  37. wait1Msec(200);
  38. motor[rightMotor] = -90;
  39. motor[leftMotor] = 90;
  40. wait1Msec(turntime);
  41. motor[rightMotor] = 0;
  42. motor[leftMotor] = 0;
  43. wait1Msec(200);
  44. }
  45. //+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
  46. //the functions are "called" by using the function name,
  47. //then the number inside () is the variable value.
  48.  
  49. task main()
  50. {
  51. int counter = 0;
  52. while (true)
  53. {
  54. motor[rightMotor] = 127;
  55. motor[leftMotor] = 127;
  56. //counter is at 0
  57.  
  58. if (SensorValue[bumpy] == 1)
  59. {counter++;} //counter increases by 1
  60.  
  61. if(counter == 1)
  62. { backup(250);
  63. leftturn(270);
  64. counter++; //counter goes to 2
  65. }
  66. if(counter == 3)
  67. { backup(250);
  68. rightturn(270);
  69. counter = 0;
  70. }
  71. }
  72.  
  73. }
Add Comment
Please, Sign In to add comment