Guest User

Untitled

a guest
Jun 25th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. #include <IRremoteESP8266.h> //INCLUSÃO DE BIBLIOTECA
  2.  
  3. int RECV_PIN = 12; //PINO DIGITAL EM QUE O FOTORRECEPTOR ESTÁ CONECTADO - GPIO12 / PINO D6
  4.  
  5. IRrecv irrecv(RECV_PIN); //VARIÁVEL DO TIPO IRrecv
  6.  
  7. decode_results results; //VARIÁVEL QUE ARMAZENA OS RESULTADOS
  8.  
  9. void setup(){
  10. Serial.begin(115200); //INICIALIZA A SERIAL
  11. irrecv.enableIRIn(); //INICIALIZA O RECEPTOR
  12. }
  13. //MÉTODO RESPONSÁVEL POR FAZER A DECODIFICAÇÃO DO SINAL IR RECEBIDO
  14. //OS DADOS SÃO PASSADOS PARA A BIBLIOTECA IRREMOTE QUE FAZ TODO O
  15. //TRATAMENTO E RETORNA AS INFORMAÇÕES DE ACORDO COM O PROTOCOLO RECONHECIDO
  16. void dump(decode_results *results) {
  17. int count = results->rawlen;
  18. if (results->decode_type == UNKNOWN) {
  19. Serial.print("Unknown encoding: ");
  20. }
  21. else if (results->decode_type == NEC) {
  22. Serial.print("Decoded NEC: ");
  23. }
  24. else if (results->decode_type == SONY) {
  25. Serial.print("Decoded SONY: ");
  26. }
  27. else if (results->decode_type == RC5) {
  28. Serial.print("Decoded RC5: ");
  29. }
  30. else if (results->decode_type == RC6) {
  31. Serial.print("Decoded RC6: ");
  32. }
  33. else if (results->decode_type == PANASONIC) {
  34. Serial.print("Decoded PANASONIC - Address: ");
  35. Serial.print(results->panasonicAddress, HEX);
  36. Serial.print(" Value: ");
  37. }
  38. else if (results->decode_type == LG) {
  39. Serial.print("Decoded LG: ");
  40. }
  41. else if (results->decode_type == JVC) {
  42. Serial.print("Decoded JVC: ");
  43. }
  44. else if (results->decode_type == AIWA_RC_T501) {
  45. Serial.print("Decoded AIWA RC T501: ");
  46. }
  47. else if (results->decode_type == WHYNTER) {
  48. Serial.print("Decoded Whynter: ");
  49. }
  50. Serial.print(results->value, HEX);
  51. Serial.print(" (");
  52. Serial.print(results->bits, DEC);
  53. Serial.println(" bits)");
  54. Serial.print("Raw (");
  55. Serial.print(count, DEC);
  56. Serial.print("): ");
  57.  
  58. for (int i = 1; i < count; i++) {
  59. if (i & 1) {
  60. Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
  61. }
  62. else {
  63. Serial.write('-');
  64. Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
  65. }
  66. Serial.print(" ");
  67. }
  68. Serial.println();
  69. }
  70.  
  71. void loop() {
  72. //RETORNA NA SERIAL AS INFORMAÇÕES FINAIS SOBRE O COMANDO IR QUE FOI IDENTIFICADO
  73. if (irrecv.decode(&results)) {
  74. Serial.println(results.value, HEX);
  75. dump(&results);
  76. irrecv.resume(); //RECEBE O PRÓXIMO VALOR
  77. }
  78. }
Add Comment
Please, Sign In to add comment