mesmariusz

Untitled

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