PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

178 líneas
5.4KB

  1. //------------------------------------------------------------------------------
  2. // Include the IRremote library header
  3. //
  4. #include <IRremote.h>
  5. //------------------------------------------------------------------------------
  6. // Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
  7. //
  8. int recvPin = 11;
  9. IRrecv irrecv(recvPin);
  10. //+=============================================================================
  11. // Configure the Arduino
  12. //
  13. void setup ( )
  14. {
  15. Serial.begin(9600); // Status message will be sent to PC at 9600 baud
  16. irrecv.enableIRIn(); // Start the receiver
  17. }
  18. //+=============================================================================
  19. // Display IR code
  20. //
  21. void ircode (decode_results *results)
  22. {
  23. // Panasonic has an Address
  24. if (results->decode_type == PANASONIC) {
  25. Serial.print(results->address, HEX);
  26. Serial.print(":");
  27. }
  28. // Print Code
  29. Serial.print(results->value, HEX);
  30. }
  31. //+=============================================================================
  32. // Display encoding type
  33. //
  34. void encoding (decode_results *results)
  35. {
  36. switch (results->decode_type) {
  37. default:
  38. case UNKNOWN: Serial.print("UNKNOWN"); break ;
  39. case NEC: Serial.print("NEC"); break ;
  40. case SONY: Serial.print("SONY"); break ;
  41. case RC5: Serial.print("RC5"); break ;
  42. case RC6: Serial.print("RC6"); break ;
  43. case DISH: Serial.print("DISH"); break ;
  44. case SHARP: Serial.print("SHARP"); break ;
  45. case JVC: Serial.print("JVC"); break ;
  46. case SANYO: Serial.print("SANYO"); break ;
  47. case MITSUBISHI: Serial.print("MITSUBISHI"); break ;
  48. case SAMSUNG: Serial.print("SAMSUNG"); break ;
  49. case LG: Serial.print("LG"); break ;
  50. case WHYNTER: Serial.print("WHYNTER"); break ;
  51. case AIWA_RC_T501: Serial.print("AIWA_RC_T501"); break ;
  52. case PANASONIC: Serial.print("PANASONIC"); break ;
  53. case DENON: Serial.print("Denon"); break ;
  54. }
  55. }
  56. //+=============================================================================
  57. // Dump out the decode_results structure.
  58. //
  59. void dumpInfo (decode_results *results)
  60. {
  61. // Check if the buffer overflowed
  62. if (results->overflow) {
  63. Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF");
  64. return;
  65. }
  66. // Show Encoding standard
  67. Serial.print("Encoding : ");
  68. encoding(results);
  69. Serial.println("");
  70. // Show Code & length
  71. Serial.print("Code : ");
  72. ircode(results);
  73. Serial.print(" (");
  74. Serial.print(results->bits, DEC);
  75. Serial.println(" bits)");
  76. }
  77. //+=============================================================================
  78. // Dump out the decode_results structure.
  79. //
  80. void dumpRaw (decode_results *results)
  81. {
  82. // Print Raw data
  83. Serial.print("Timing[");
  84. Serial.print(results->rawlen-1, DEC);
  85. Serial.println("]: ");
  86. for (int i = 1; i < results->rawlen; i++) {
  87. unsigned long x = results->rawbuf[i] * USECPERTICK;
  88. if (!(i & 1)) { // even
  89. Serial.print("-");
  90. if (x < 1000) Serial.print(" ") ;
  91. if (x < 100) Serial.print(" ") ;
  92. Serial.print(x, DEC);
  93. } else { // odd
  94. Serial.print(" ");
  95. Serial.print("+");
  96. if (x < 1000) Serial.print(" ") ;
  97. if (x < 100) Serial.print(" ") ;
  98. Serial.print(x, DEC);
  99. if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one
  100. }
  101. if (!(i % 8)) Serial.println("");
  102. }
  103. Serial.println(""); // Newline
  104. }
  105. //+=============================================================================
  106. // Dump out the decode_results structure.
  107. //
  108. void dumpCode (decode_results *results)
  109. {
  110. // Start declaration
  111. Serial.print("unsigned int "); // variable type
  112. Serial.print("rawData["); // array name
  113. Serial.print(results->rawlen - 1, DEC); // array size
  114. Serial.print("] = {"); // Start declaration
  115. // Dump data
  116. for (int i = 1; i < results->rawlen; i++) {
  117. Serial.print(results->rawbuf[i] * USECPERTICK, DEC);
  118. if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one
  119. if (!(i & 1)) Serial.print(" ");
  120. }
  121. // End declaration
  122. Serial.print("};"); //
  123. // Comment
  124. Serial.print(" // ");
  125. encoding(results);
  126. Serial.print(" ");
  127. ircode(results);
  128. // Newline
  129. Serial.println("");
  130. // Now dump "known" codes
  131. if (results->decode_type != UNKNOWN) {
  132. // Some protocols have an address
  133. if (results->decode_type == PANASONIC) {
  134. Serial.print("unsigned int addr = 0x");
  135. Serial.print(results->address, HEX);
  136. Serial.println(";");
  137. }
  138. // All protocols have data
  139. Serial.print("unsigned int data = 0x");
  140. Serial.print(results->value, HEX);
  141. Serial.println(";");
  142. }
  143. }
  144. //+=============================================================================
  145. // The repeating section of the code
  146. //
  147. void loop ( )
  148. {
  149. decode_results results; // Somewhere to store the results
  150. if (irrecv.decode(&results)) { // Grab an IR code
  151. dumpInfo(&results); // Output the results
  152. dumpRaw(&results); // Output the results in RAW format
  153. dumpCode(&results); // Output the results as source code
  154. Serial.println(""); // Blank line between entries
  155. irrecv.resume(); // Prepare for the next value
  156. }
  157. }