that_one_nigga_you_k

definitivo

Jul 12th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. // definir a distância do objeto
  2. #define INPUT_REDCOLOR 5
  3. #define INPUT_GREENCOLOR 3
  4. #define INPUT_BLACKCOLOR 1
  5. #define INPUT_WHITECOLOR 6
  6.  
  7.  
  8. /* sub verde(int pwr)
  9. {
  10. SetSensor(S2, SENSOR_COLORFULL);
  11. SetSensor(S3, SENSOR_COLORFULL);
  12. SetSensorLowspeed(IN_1);
  13. SetSensorLowspeed(IN_4);
  14.  
  15. OnRev(OUT_AC, 75);
  16. Wait(1000);
  17.  
  18. }
  19.  
  20. sub garra (int pwr)
  21. {
  22.  
  23. while(true)
  24. {
  25. if(Sensor(IN_2)<=30 && Sensor(IN_3)<=30)
  26. {
  27. OnFwd(OUT_AC, 75);
  28. }
  29.  
  30. else if(SensorUS(IN_1)<10)
  31. {
  32. RotateMotor(OUT_C, 75, 600);
  33. OnRev(OUT_AC, 75);
  34. }
  35.  
  36. else if(SensorUS(IN_4)<7)
  37. {
  38. RotateMotor(OUT_B, 75, 50);
  39. RotateMotor(OUT_A, 75, 600);
  40. OnFwd(OUT_AC, 75);
  41. }
  42. }
  43.  
  44.  
  45. }
  46. */
  47.  
  48.  
  49. task main()
  50. {
  51. SetSensor(S2, SENSOR_COLORRED);
  52. SetSensor(S3, SENSOR_COLORRED);
  53. SetSensorLowspeed(IN_1);
  54. SetSensorLowspeed(IN_4);
  55. //white==48; apenas para decorar
  56. // black==18;
  57. //green==18;
  58.  
  59. while(true)
  60. {
  61.  
  62. if(Sensor(IN_2)>=30 && Sensor(IN_3)>=30) // ao ver branco, andar pra frente
  63. {
  64. OnFwd(OUT_AC, 75);
  65.  
  66. if(SensorUS(IN_1)<13)
  67. {
  68. OnFwd(OUT_C, 75); // forward 90 degrees
  69. OnRev(OUT_A, 75);
  70. Wait(900);
  71. OnFwd(OUT_AC, 75);
  72. Wait(250);
  73.  
  74. RotateMotor(OUT_C, 50, 790);
  75. OnFwd(OUT_AC, 75);
  76. Wait(250);
  77.  
  78. RotateMotor(OUT_C, 50, 790);
  79. OnFwd(OUT_AC, 75);
  80. Wait(250);
  81.  
  82. if(Sensor(IN_2)>=30 && Sensor(IN_3)>=30)
  83. {
  84. RotateMotor(OUT_A, 50, 790);
  85. }
  86. }
  87.  
  88. }
  89.  
  90. else if(Sensor(IN_2)<=30 && Sensor(IN_3)<=30) //os dois sensores vendo preto
  91.  
  92. {
  93. SetSensor(S2, SENSOR_COLORFULL); //transforma os sensores de luz em sensor de cor
  94. SetSensor(S3, SENSOR_COLORFULL);
  95. SetSensorLowspeed(IN_1);
  96. SetSensorLowspeed(IN_4);
  97.  
  98. OnRev(OUT_AC, 75);
  99. Wait(100);
  100. OnFwd(OUT_AC, 75);
  101.  
  102. if(Sensor(IN_2) == 3) //DIREITA vendo verde
  103. {
  104. OnRev(OUT_A, 50);
  105. OnFwd(OUT_C, 50);
  106. }
  107.  
  108. else if(Sensor(IN_3) == 3) // ESQUERDA vendo verde
  109. {
  110. OnRev(OUT_C, 50);
  111. OnFwd(OUT_A, 50);
  112. }
  113.  
  114. }
  115.  
  116. else if(Sensor(IN_2)<=30) // sensor 2, ao ver preto, desacelera lado DIREITO do robô
  117. {
  118. OnFwd(OUT_C, 50);
  119. OnRev(OUT_A, 50);
  120. }
  121.  
  122. else if(Sensor(IN_3)<=30) // sensor 3, ao ver preto, desacelera lado ESQUERDO do robô
  123. {
  124. OnFwd(OUT_A, 50);
  125. OnRev(OUT_C, 50);
  126.  
  127. }
  128.  
  129.  
  130.  
  131. /*if (Sensor(IN_2) == 40 && Sensor(IN_3) == 40)
  132. {
  133. garra (60);
  134. }
  135. */
  136. }
  137. }
Add Comment
Please, Sign In to add comment