IRGCSendDemo.ino 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * IRremoteESP8266: IRsendGCDemo
  3. * demonstrates sending Global Cache-formatted IR codes with IRsend
  4. * Copyright 2009 Ken Shirriff
  5. * http://arcfn.com
  6. *
  7. * Version 0.2 June, 2017
  8. * Added helpful comments
  9. * Better includes files.
  10. * Version 0.1 30 March, 2016
  11. * Based on Ken Shirriff's IrsendDemo
  12. * Version 0.1 July, 2009
  13. *
  14. * An IR LED circuit *MUST* be connected to the ESP8266 on a pin
  15. * as specified by IR_LED below.
  16. *
  17. * TL;DR: The IR LED needs to be driven by a transistor for a good result.
  18. *
  19. * Suggested circuit:
  20. * https://github.com/markszabo/IRremoteESP8266/wiki#ir-sending
  21. *
  22. * Common mistakes & tips:
  23. * * Don't just connect the IR LED directly to the pin, it won't
  24. * have enough current to drive the IR LED effectively.
  25. * * Make sure you have the IR LED polarity correct.
  26. * See: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
  27. * * Typical digital camera/phones can be used to see if the IR LED is
  28. * flashed. Replace the IR LED with a normal LED if you don't have a digital
  29. * camera when debugging.
  30. * * Avoid using the following pins unless you really know what you are doing:
  31. * * Pin 0/D3: Can interfere with the boot/program mode & support circuits.
  32. * * Pin 1/TX/TXD0: Any serial transmissions from the ESP8266 will
  33. * interfere.
  34. * * Pin 3/RX/RXD0: Any serial transmissions to the ESP8266 will interfere.
  35. * * ESP-01 modules are tricky. We suggest you use a module with more GPIOs
  36. * for your first time. e.g. ESP-12 etc.
  37. */
  38. #ifndef UNIT_TEST
  39. #include <Arduino.h>
  40. #endif
  41. #include <IRremoteESP8266.h>
  42. #include <IRsend.h>
  43. // Codes are in Global Cache format less the emitter ID and request ID.
  44. // These codes can be found in GC's Control Tower database.
  45. uint16_t Samsung_power_toggle[71] = {
  46. 38000, 1, 1, 170, 170, 20, 63, 20, 63, 20, 63, 20, 20, 20, 20,
  47. 20, 20, 20, 20, 20, 20, 20, 63, 20, 63, 20, 63, 20, 20, 20,
  48. 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 63, 20, 20, 20, 20,
  49. 20, 20, 20, 20, 20, 20, 20, 20, 20, 63, 20, 20, 20, 63, 20,
  50. 63, 20, 63, 20, 63, 20, 63, 20, 63, 20, 1798};
  51. #define IR_LED 4 // ESP8266 GPIO pin to use. Recommended: 4 (D2).
  52. IRsend irsend(IR_LED); // Set the GPIO to be used to sending the message.
  53. void setup() {
  54. irsend.begin();
  55. Serial.begin(115200);
  56. }
  57. void loop() {
  58. Serial.println("Toggling power");
  59. #if SEND_GLOBALCACHE
  60. irsend.sendGC(Samsung_power_toggle, 71);
  61. #else // SEND_GLOBALCACHE
  62. Serial.println("Can't send because SEND_GLOBALCACHE has been disabled.");
  63. #endif // SEND_GLOBALCACHE
  64. delay(10000);
  65. }