Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include <IRremote.h>
  2.  
  3.  
  4.  
  5. int RECV_PIN = A3;
  6.  
  7. IRrecv irrecv(RECV_PIN);
  8.  
  9. decode_results results;
  10.  
  11. IRsend irsend;
  12.  
  13. int IRLED = 3;
  14.  
  15. int buttonPin = 8;
  16.  
  17. int buttonState = 0;
  18.  
  19.  
  20.  
  21.  
  22.  
  23. void setup()
  24.  
  25. {
  26.  
  27. Serial.begin(9600);
  28.  
  29. irrecv.enableIRIn(); // Start the receiver
  30.  
  31. pinMode(IRLED, OUTPUT);
  32.  
  33. pinMode(buttonPin, INPUT);
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41. //Infinite loop
  42.  
  43. void loop()
  44.  
  45. { buttonState = digitalRead(buttonPin);
  46.  
  47. if (buttonPin == HIGH) {
  48.  
  49. irsend.sendNEC(0x61A0F00F, 32); // TV power code
  50.  
  51. delay(100);
  52.  
  53. }
  54.  
  55.  
  56.  
  57. {
  58.  
  59. if (irrecv.decode(&results)) {
  60.  
  61. Serial.println(results.value, DEC);}
  62.  
  63. dump(&results);
  64.  
  65. irrecv.resume(); // Receive the next value
  66.  
  67. }
  68.  
  69. }
  70.  
  71.  
  72.  
  73. //Dumps the result and prints the numeric received dada and type of remote
  74.  
  75. void dump(decode_results * results) {
  76.  
  77. // Dumps out the decode_results structure.
  78.  
  79. // Call this after IRrecv::decode()
  80.  
  81. int count = results->rawlen;
  82.  
  83. if (results->decode_type == UNKNOWN) {
  84.  
  85. Serial.print("Unknown encoding: ");
  86.  
  87. }
  88.  
  89. else if (results->decode_type == NEC) {
  90.  
  91. Serial.print("Decoded NEC: ");
  92.  
  93. }
  94.  
  95. else if (results->decode_type == SONY) {
  96.  
  97. Serial.print("Decoded SONY: ");
  98.  
  99. }
  100.  
  101. else if (results->decode_type == RC5) {
  102.  
  103. Serial.print("Decoded RC5: ");
  104.  
  105. }
  106.  
  107. else if (results->decode_type == RC6) {
  108.  
  109. Serial.print("Decoded RC6: ");
  110.  
  111. }
  112.  
  113. else if (results->decode_type == PANASONIC) {
  114.  
  115. Serial.print("Decoded PANASONIC - Address: ");
  116.  
  117. Serial.print(results->address, HEX);
  118.  
  119. Serial.print(" Value: ");
  120.  
  121. }
  122.  
  123. else if (results->decode_type == LG) {
  124.  
  125. Serial.print("Decoded LG: ");
  126.  
  127. }
  128.  
  129. else if (results->decode_type == JVC) {
  130.  
  131. Serial.print("Decoded JVC: ");
  132.  
  133. }
  134.  
  135. else if (results->decode_type == AIWA_RC_T501) {
  136.  
  137. Serial.print("Decoded AIWA RC T501: ");
  138.  
  139. }
  140.  
  141. else if (results->decode_type == WHYNTER) {
  142.  
  143. Serial.print("Decoded Whynter: ");
  144.  
  145. }
  146.  
  147. Serial.print(results->value, HEX);
  148.  
  149. Serial.print(" (");
  150.  
  151. Serial.print(results->bits, DEC);
  152.  
  153. Serial.println(" bits)");
  154.  
  155. Serial.print("Raw (");
  156.  
  157. Serial.print(count, DEC);
  158.  
  159. Serial.print("): ");
  160.  
  161.  
  162.  
  163. for (int i = 1; i < count; i++) {
  164.  
  165. if (i & 1) {
  166.  
  167. Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
  168.  
  169. }
  170.  
  171. else {
  172.  
  173. Serial.write('-');
  174.  
  175. Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
  176.  
  177. }
  178.  
  179. Serial.print(" ");
  180.  
  181. }
  182.  
  183. Serial.println();
  184.  
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement