Advertisement
macikss

sterowanie robotem przez ir

Feb 13th, 2015
241
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.  
  11. void setup() {
  12. Serial.begin(9600);
  13. irrecv.enableIRIn();
  14.  
  15. motor.setSpeed(200);
  16. motor1.setSpeed(200);
  17. motor.run(RELEASE);
  18. motor1.run(RELEASE);
  19. }
  20.  
  21. void loop() {
  22. if (irrecv.decode(&results)) {
  23.  
  24. switch (results.value) {
  25. case 0xFF629D:
  26. Serial.println("jazda w przod");
  27. motor.run(FORWARD);
  28. motor1.run(FORWARD);
  29. break;
  30.  
  31. }
  32.  
  33. switch (results.value) {
  34. case 0xFF6897:
  35. Serial.println("jazda w tyl");
  36. motor.run(BACKWARD);
  37. motor1.run(BACKWARD);
  38. break;
  39. }
  40. switch (results.value) {
  41. case 0xFFA857:
  42. Serial.println("jazda w prawo");
  43. motor.run(BACKWARD);
  44. motor1.run(FORWARD);
  45. break;
  46. }
  47. switch (results.value) {
  48. case 0xFFE21D:
  49. Serial.println("jazda w lewo");
  50. motor.run(FORWARD);
  51. motor1.run(BACKWARD);
  52. break;
  53. }
  54. switch (results.value) {
  55. case 0xFFE817:
  56. Serial.println("sTOP");
  57. motor.run(RELEASE);
  58. motor1.run(RELEASE);
  59. break;
  60. }
  61. irrecv.resume();
  62. }
  63. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement