Advertisement
RuiViana

Receptor RF433

Apr 9th, 2016
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. // INICIO RECEPTOR_________________________________________
  2. #include <AFMotor.h>
  3. #include <VirtualWire.h>
  4. AF_DCMotor motor1(1);
  5. AF_DCMotor motor2(2);
  6. AF_DCMotor motor3(3);
  7. AF_DCMotor motor4(4);
  8. //----------------------------------------------
  9. void setup()
  10. {
  11. int i;
  12. // Configurareceptor
  13. vw_set_ptt_inverted(true);
  14. vw_setup(2000);
  15. vw_set_rx_pin(50); //Configura o pino 30 como rx
  16. vw_rx_start(); // inicia recepcao
  17. pinMode(50, INPUT); // configura pino30 para recepcao
  18. Serial.begin(9600);
  19. }
  20. //----------------------------------------------
  21. void loop()
  22. {
  23. char cod; // Cria uma variavel armazenar o dado recebido.
  24. uint8_t buf[VW_MAX_MESSAGE_LEN]; // Recebe os dados e armazena na var buf
  25. uint8_t buflen = VW_MAX_MESSAGE_LEN; // Armazena na tamanho dado recebido
  26. if (vw_get_message(buf, &buflen)) // Observa dado recebido
  27. {
  28. cod = buf[0]; // Converte em Char
  29. Serial.println(cod); // Para observar possiveis erros
  30.  
  31. switch (cod)
  32. {
  33. case 'F':
  34. motor1.setSpeed(75);
  35. motor2.setSpeed(75);
  36. motor3.setSpeed(75);
  37. motor4.setSpeed(75);
  38. motor1.run(FORWARD);
  39. motor2.run(FORWARD);
  40. motor3.run(FORWARD);
  41. motor4.run(FORWARD);
  42. break;
  43. case 'T':
  44. motor1.setSpeed(75);
  45. motor2.setSpeed(75);
  46. motor3.setSpeed(75);
  47. motor4.setSpeed(75);
  48. motor1.run(BACKWARD);
  49. motor2.run(BACKWARD);
  50. motor3.run(BACKWARD);
  51. motor4.run(BACKWARD);
  52. break;
  53. case 'D':
  54. motor1.setSpeed(75);
  55. motor2.setSpeed(75);
  56. motor3.setSpeed(75);
  57. motor4.setSpeed(75);
  58. motor1.run(FORWARD);
  59. motor2.run(BACKWARD);
  60. motor3.run(FORWARD);
  61. motor4.run(BACKWARD);
  62. break;
  63. case 'E':
  64. motor1.setSpeed(75);
  65. motor2.setSpeed(75);
  66. motor3.setSpeed(75);
  67. motor4.setSpeed(75);
  68. motor1.run(BACKWARD);
  69. motor2.run(FORWARD);
  70. motor3.run(BACKWARD);
  71. motor4.run(FORWARD);
  72. break;
  73. case 'X':
  74. motor1.run(RELEASE);
  75. motor2.run(RELEASE);
  76. motor3.run(RELEASE);
  77. motor4.run(RELEASE);
  78. break;
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement