IRsendProntoDemo.ino 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* IRremoteESP8266: IRsendProntoDemo
  2. * Copyright 2017 David Conran
  3. *
  4. * Demonstrates sending Pronto codes with IRsend.
  5. *
  6. * Version 1.0 June, 2017
  7. *
  8. * An IR LED circuit *MUST* be connected to ESP8266 pin 4 (D2), unless you
  9. * change the kIrLed value below.
  10. *
  11. * TL;DR: The IR LED needs to be driven by a transistor for a good result.
  12. *
  13. * Suggested circuit:
  14. * https://github.com/markszabo/IRremoteESP8266/wiki#ir-sending
  15. *
  16. * Common mistakes & tips:
  17. * * Don't just connect the IR LED directly to the pin, it won't
  18. * have enough current to drive the IR LED effectively.
  19. * * Make sure you have the IR LED polarity correct.
  20. * See: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
  21. * * Typical digital camera/phones can be used to see if the IR LED is flashed.
  22. * Replace the IR LED with a normal LED if you don't have a digital camera
  23. * when debugging.
  24. * * Avoid using the following pins unless you really know what you are doing:
  25. * * Pin 0/D3: Can interfere with the boot/program mode & support circuits.
  26. * * Pin 1/TX/TXD0: Any serial transmissions from the ESP8266 will interfere.
  27. * * Pin 3/RX/RXD0: Any serial transmissions to the ESP8266 will interfere.
  28. * * ESP-01 modules are tricky. We suggest you use a module with more GPIOs
  29. * for your first time. e.g. ESP-12 etc.
  30. */
  31. #ifndef UNIT_TEST
  32. #include <Arduino.h>
  33. #endif
  34. #include <IRremoteESP8266.h>
  35. #include <IRsend.h>
  36. const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
  37. IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
  38. // Panasonic Plasma TV Descrete code (Power On).
  39. // Acquired from:
  40. // https://irdb.globalcache.com/
  41. // e.g.
  42. // 0000 006D 0000 0022 00ac 00ac 0016 0040 0016 0040 0016 0040 0016 0015 0016
  43. // 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0040 0016 0040 0016 0015
  44. // 0016 0015 0016 0015 0016 0015 0016 0015 0016 0040 0016 0015 0016 0015 0016
  45. // 0040 0016 0040 0016 0015 0016 0015 0016 0040 0016 0015 0016 0040 0016 0040
  46. // 0016 0015 0016 0015 0016 0040 0016 0040 0016 0015 0016 071c
  47. //
  48. // Or the equiv. of sendSamsung(0xE0E09966);
  49. uint16_t samsungProntoCode[72] = {
  50. 0x0000, 0x006D, 0x0000, 0x0022,
  51. 0x00ac, 0x00ac, 0x0016, 0x0040, 0x0016, 0x0040, 0x0016, 0x0040,
  52. 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015,
  53. 0x0016, 0x0015, 0x0016, 0x0040, 0x0016, 0x0040, 0x0016, 0x0040,
  54. 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0015,
  55. 0x0016, 0x0015, 0x0016, 0x0040, 0x0016, 0x0015, 0x0016, 0x0015,
  56. 0x0016, 0x0040, 0x0016, 0x0040, 0x0016, 0x0015, 0x0016, 0x0015,
  57. 0x0016, 0x0040, 0x0016, 0x0015, 0x0016, 0x0040, 0x0016, 0x0040,
  58. 0x0016, 0x0015, 0x0016, 0x0015, 0x0016, 0x0040, 0x0016, 0x0040,
  59. 0x0016, 0x0015, 0x0016, 0x071c
  60. };
  61. // Panasonic Plasma TV Descrete code (Power On).
  62. // Acquired from:
  63. // ftp://ftp.panasonic.com/pub/panasonic/drivers/monitors/Discrete-remote-control-codesProntoCCFformat.pdf
  64. // e.g.
  65. // 0000 0071 0000 0032 0080 003F 0010 0010 0010 0030 0010 0010 0010 0010 0010
  66. // 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010
  67. // 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010
  68. // 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010
  69. // 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010
  70. // 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0010 0010 0030
  71. // 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0030 0010 0A98
  72. //
  73. // Or the equiv. of sendPanasonic64(0x400401007C7D);
  74. uint16_t panasonicProntoCode[104] = {
  75. 0x0000, 0x0071, 0x0000, 0x0032,
  76. 0x0080, 0x003F, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0010,
  77. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  78. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  79. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0010,
  80. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  81. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  82. 0x0010, 0x0030, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  83. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
  84. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0030,
  85. 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0010,
  86. 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0030,
  87. 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0010,
  88. 0x0010, 0x0030, 0x0010, 0x0A98};
  89. void setup() {
  90. irsend.begin();
  91. Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
  92. }
  93. void loop() {
  94. #if SEND_PRONTO
  95. Serial.println("Sending a Samsung TV 'on' command.");
  96. irsend.sendPronto(samsungProntoCode, 72);
  97. delay(2000);
  98. Serial.println("Sending a Panasonic Plasma TV 'on' command.");
  99. irsend.sendPronto(panasonicProntoCode, 104);
  100. delay(2000);
  101. #else // SEND_PRONTO
  102. Serial.println("Can't send because SEND_PRONTO has been disabled.");
  103. delay(10000);
  104. #endif // SEND_PRONTO
  105. }