Advertisement
Guest User

sumo

a guest
Jun 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include "MeMCore.h"
  2. MeDCMotor stang(M1);
  3. MeDCMotor drept(M2);
  4. MeLineFollower line(PORT_2);
  5. MeUltrasonicSensor sonic(PORT_3);
  6. int distanta;
  7. int stare;
  8. MeIR ir;
  9. int ok;
  10. int Stefan=0;
  11. int m=0;
  12. uint32_t value = 0x00;
  13. void inainte () {
  14. stang.run(-150);
  15. drept.run(150);
  16. }
  17.  
  18.  
  19. void atac () {
  20. stang.run(-255);
  21. drept.run(255);
  22. }
  23.  
  24. void inapoi () {
  25. stang.run(255);
  26. drept.run(-255);
  27. }
  28. void dreapta () {
  29. stang.run(255);
  30. drept.run(0);
  31. }
  32. void stanga () {
  33. stang.run(0);
  34. drept.run(-255);
  35. }
  36. void oprire () {
  37. stang.run(0);
  38. drept.run(0);
  39. }
  40.  
  41.  
  42.  
  43. void sumo() {
  44.  
  45. distanta = sonic.distanceCm();
  46. int stare = line.readSensors();
  47. switch (stare) {
  48. case 0:{
  49. if (distanta < 20) {
  50. atac(); }
  51. else inainte(); break;}
  52. case 1: inapoi(); delay(600);dreapta();delay(300); ok = 1; break;
  53. case 2: inapoi(); delay(600);stanga();delay(300);ok = 2; break;
  54. case 3: inapoi(); delay(600);stanga();delay(300);break;
  55. //if (ok == 1){inapoi(); delay(600);dreapta();delay(300);}
  56. // if (ok == 2){inapoi; delay(600);stanga();delay(300);}
  57. //if(ok == 0) {inapoi; delay(600);stanga();delay(300);}
  58.  
  59.  
  60. }}
  61. /*distanta = sonic.distanceCm();
  62. if (distanta < 20) {
  63. atac(); }
  64. else inainte();
  65. }
  66. */
  67.  
  68. void setup() {
  69. ir.begin();}
  70.  
  71. void loop() {
  72. if (ir.decode()) {
  73. value = (ir.value >> 16 & 0xFF );
  74.  
  75. }
  76. switch (value) {
  77. case 0x44 : if (Stefan==0)
  78. {dreapta();
  79. delay(600);
  80. Stefan=Stefan+1;}
  81. sumo();
  82. break;
  83. }
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement