IRsendDemo.ino 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* IRremoteESP8266: IRsendDemo - demonstrates sending IR codes with IRsend.
  2. *
  3. * Version 1.0 April, 2017
  4. * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009,
  5. * Copyright 2009 Ken Shirriff, http://arcfn.com
  6. *
  7. * An IR LED circuit *MUST* be connected to the ESP8266 on a pin
  8. * as specified by kIrLed below.
  9. *
  10. * TL;DR: The IR LED needs to be driven by a transistor for a good result.
  11. *
  12. * Suggested circuit:
  13. * https://github.com/markszabo/IRremoteESP8266/wiki#ir-sending
  14. *
  15. * Common mistakes & tips:
  16. * * Don't just connect the IR LED directly to the pin, it won't
  17. * have enough current to drive the IR LED effectively.
  18. * * Make sure you have the IR LED polarity correct.
  19. * See: https://learn.sparkfun.com/tutorials/polarity/diode-and-led-polarity
  20. * * Typical digital camera/phones can be used to see if the IR LED is flashed.
  21. * Replace the IR LED with a normal LED if you don't have a digital camera
  22. * when debugging.
  23. * * Avoid using the following pins unless you really know what you are doing:
  24. * * Pin 0/D3: Can interfere with the boot/program mode & support circuits.
  25. * * Pin 1/TX/TXD0: Any serial transmissions from the ESP8266 will interfere.
  26. * * Pin 3/RX/RXD0: Any serial transmissions to the ESP8266 will interfere.
  27. * * ESP-01 modules are tricky. We suggest you use a module with more GPIOs
  28. * for your first time. e.g. ESP-12 etc.
  29. */
  30. #ifndef UNIT_TEST
  31. #include <Arduino.h>
  32. #endif
  33. #include <IRremoteESP8266.h>
  34. #include <IRsend.h>
  35. const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
  36. IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
  37. // Example of data captured by IRrecvDumpV2.ino
  38. uint16_t rawData[67] = {9000, 4500, 650, 550, 650, 1650, 600, 550, 650, 550,
  39. 600, 1650, 650, 550, 600, 1650, 650, 1650, 650, 1650,
  40. 600, 550, 650, 1650, 650, 1650, 650, 550, 600, 1650,
  41. 650, 1650, 650, 550, 650, 550, 650, 1650, 650, 550,
  42. 650, 550, 650, 550, 600, 550, 650, 550, 650, 550,
  43. 650, 1650, 600, 550, 650, 1650, 650, 1650, 650, 1650,
  44. 650, 1650, 650, 1650, 650, 1650, 600};
  45. void setup() {
  46. irsend.begin();
  47. Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
  48. }
  49. void loop() {
  50. #if SEND_NEC
  51. Serial.println("NEC");
  52. irsend.sendNEC(0x00FFE01FUL, 32);
  53. #endif // SEND_NEC
  54. delay(2000);
  55. #if SEND_SONY
  56. Serial.println("Sony");
  57. irsend.sendSony(0xa90, 12, 2);
  58. #endif // SEND_SONY
  59. delay(2000);
  60. #if SEND_RAW
  61. Serial.println("a rawData capture from IRrecvDumpV2");
  62. irsend.sendRaw(rawData, 67, 38); // Send a raw data capture at 38kHz.
  63. #endif // SEND_RAW
  64. delay(2000);
  65. }