Advertisement
Guest User

Untitled

a guest
Feb 13th, 2015
271
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. unsigned long lastCommand = 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. lastCommand = millis();
  25. switch (results.value) {
  26. case 0xFF629D:
  27. Serial.println("jazda w przod");
  28. motor.run(FORWARD);
  29. motor1.run(FORWARD);
  30. break;
  31.  
  32. case 0xFF6897:
  33. Serial.println("jazda w tyl");
  34. motor.run(BACKWARD);
  35. motor1.run(BACKWARD);
  36. break;
  37.  
  38. case 0xFFA857:
  39. Serial.println("jazda w prawo");
  40. motor.run(BACKWARD);
  41. motor1.run(FORWARD);
  42. break;
  43.  
  44. case 0xFFE21D:
  45. Serial.println("jazda w lewo");
  46. motor.run(FORWARD);
  47. motor1.run(BACKWARD);
  48. break;
  49.  
  50. case 0xFFE817:
  51. Serial.println("sTOP");
  52. motor.run(RELEASE);
  53. motor1.run(RELEASE);
  54. break;
  55. }
  56. irrecv.resume();
  57. }
  58.  
  59. if(lastCommand && millis() - lastCommand > 500) // w sumie minimalnie penisek, bo jest szansa że ktoś się idealnie wstrzeli w overflow, ale welp :3
  60. {
  61. motor.run(RELEASE);
  62. motor1.run(RELEASE);
  63. lastCommand = 0;
  64. }
  65. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement