mesmariusz

Pojazd

Jul 12th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <IRremote.h>
  2. #define irPin 11
  3. #define go_time 1000
  4. #define turn_time 200
  5. #define motor_left_A 2
  6. #define motor_left_B 3
  7. #define motor_right_A 4
  8. #define motor_right_B 5
  9. #define reset_button 6
  10. IRrecv irrecv(irPin);
  11. decode_results results;
  12.  
  13. void setup() {
  14. Serial.begin(9600);
  15. irrecv.enableIRIn();
  16. pinMode(motor_left_A, OUTPUT);
  17. pinMode(motor_left_B, OUTPUT);
  18. pinMode(motor_right_A, OUTPUT);
  19. pinMode(motor_right_B, OUTPUT);
  20. pinMode(reset_button, INPUT);
  21. if (digitalRead(reset_button) == LOW) {
  22. reset();
  23. }
  24. }
  25.  
  26. void go() {
  27. digitalWrite(motor_left_A, LOW);
  28. digitalWrite(motor_left_B, HIGH);
  29. digitalWrite(motor_right_A, LOW);
  30. digitalWrite(motor_right_B, HIGH);
  31. }
  32.  
  33. void back() {
  34. digitalWrite(motor_left_A, HIGH);
  35. digitalWrite(motor_left_B, LOW);
  36. digitalWrite(motor_right_A, HIGH);
  37. digitalWrite(motor_right_B, LOW);
  38. }
  39.  
  40. void left() {
  41. digitalWrite(motor_left_A, LOW);
  42. digitalWrite(motor_left_B, HIGH);
  43. digitalWrite(motor_right_A, HIGH);
  44. digitalWrite(motor_right_B, LOW);
  45. }
  46.  
  47. void right() {
  48. digitalWrite(motor_left_A, HIGH);
  49. digitalWrite(motor_left_B, LOW);
  50. digitalWrite(motor_right_A, LOW);
  51. digitalWrite(motor_right_B, HIGH);
  52. }
  53.  
  54. void stop() {
  55. digitalWrite(motor_left_A, LOW);
  56. digitalWrite(motor_left_B, LOW);
  57. digitalWrite(motor_right_A, LOW);
  58. digitalWrite(motor_right_B, LOW);
  59. }
  60.  
  61. void reset() {
  62. go();
  63. back();
  64. left();
  65. right();
  66. stop();
  67. }
  68.  
  69.  
  70.  
  71. void loop() {
  72. if (irrecv.decode(&results)) {
  73.  
  74. Serial.print("0x");
  75. Serial.println(results.value, HEX);
  76. delay(250);
  77.  
  78. // dol
  79. switch (results.value) {
  80. case 0x2FDF807 :
  81. back();
  82. delay(go_time);
  83. stop();
  84. break;
  85. }
  86.  
  87. // gora
  88. switch (results.value) {
  89. case 0x2FDD827 :
  90. go();
  91. delay(go_time);
  92. stop();
  93. break;
  94. }
  95.  
  96. // lewo
  97. switch (results.value) {
  98. case 0x2FD58A7 :
  99. left();
  100. delay(turn_time);
  101. stop();
  102. break;
  103. }
  104.  
  105. //prawo
  106. switch (results.value) {
  107. case 0x2FD7887 :
  108. right();
  109. delay(turn_time);
  110. stop();
  111. break;
  112. }
  113.  
  114. //stop
  115. switch (results.value) {
  116. case 0x2FD48B7 :
  117. stop();
  118. break;
  119. }
  120.  
  121. irrecv.resume();
  122. }
  123. }
Add Comment
Please, Sign In to add comment