Advertisement
Guest User

Untitled

a guest
Feb 13th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <AFMotor.h>
  2. #include <IRremote.h>
  3. #define irPin 2
  4.  
  5. IRrecv irrecv(irPin);
  6. decode_results results;
  7. AF_DCMotor motor(4);
  8. AF_DCMotor motor1(3);
  9.  
  10. int counter = 0;
  11.  
  12. void setup() {
  13. Serial.begin(9600);
  14. irrecv.enableIRIn();
  15.  
  16. motor.setSpeed(200);
  17. motor1.setSpeed(200);
  18. motor.run(RELEASE);
  19. motor1.run(RELEASE);
  20. }
  21.  
  22. void loop() {
  23. if (irrecv.decode(&results)) {
  24.  
  25. switch (results.value) {
  26. case 0xFF629D:
  27. Serial.println("jazda w przod");
  28. motor.run(FORWARD);
  29. motor1.run(FORWARD);
  30. counter = 0;
  31. break;
  32.  
  33. case 0xFF6897:
  34. Serial.println("jazda w tyl");
  35. motor.run(BACKWARD);
  36. motor1.run(BACKWARD);
  37. counter = 0;
  38. break;
  39.  
  40. case 0xFFA857:
  41. Serial.println("jazda w prawo");
  42. motor.run(BACKWARD);
  43. motor1.run(FORWARD);
  44. counter = 0;
  45. break;
  46.  
  47. case 0xFFE21D:
  48. Serial.println("jazda w lewo");
  49. motor.run(FORWARD);
  50. motor1.run(BACKWARD);
  51. counter = 0;
  52. break;
  53.  
  54. case 0xFFE817:
  55. Serial.println("sTOP");
  56. motor.run(RELEASE);
  57. motor1.run(RELEASE);
  58. break;
  59. }
  60. irrecv.resume();
  61. }
  62.  
  63. if(counter == 50)
  64. {
  65. motor.run(RELEASE);
  66. motor1.run(RELEASE);
  67. }
  68.  
  69. counter++;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement