IRrecvDemo.ino 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * IRremoteESP8266: IRrecvDemo - demonstrates receiving IR codes with IRrecv
  3. * This is very simple teaching code to show you how to use the library.
  4. * If you are trying to decode your Infra-Red remote(s) for later replay,
  5. * use the IRrecvDumpV2.ino example code instead of this.
  6. * An IR detector/demodulator must be connected to the input kRecvPin.
  7. * Copyright 2009 Ken Shirriff, http://arcfn.com
  8. * Example circuit diagram:
  9. * https://github.com/markszabo/IRremoteESP8266/wiki#ir-receiving
  10. * Changes:
  11. * Version 0.2 June, 2017
  12. * Changed GPIO pin to the same as other examples.
  13. * Used our own method for printing a uint64_t.
  14. * Changed the baud rate to 115200.
  15. * Version 0.1 Sept, 2015
  16. * Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009
  17. */
  18. #ifndef UNIT_TEST
  19. #include <Arduino.h>
  20. #endif
  21. #include <IRremoteESP8266.h>
  22. #include <IRrecv.h>
  23. #include <IRutils.h>
  24. // An IR detector/demodulator is connected to GPIO pin 14(D5 on a NodeMCU
  25. // board).
  26. const uint16_t kRecvPin = 14;
  27. IRrecv irrecv(kRecvPin);
  28. decode_results results;
  29. void setup() {
  30. Serial.begin(115200);
  31. irrecv.enableIRIn(); // Start the receiver
  32. while (!Serial) // Wait for the serial connection to be establised.
  33. delay(50);
  34. Serial.println();
  35. Serial.print("IRrecvDemo is now running and waiting for IR message on Pin ");
  36. Serial.println(kRecvPin);
  37. }
  38. void loop() {
  39. if (irrecv.decode(&results)) {
  40. // print() & println() can't handle printing long longs. (uint64_t)
  41. serialPrintUint64(results.value, HEX);
  42. Serial.println("");
  43. irrecv.resume(); // Receive the next value
  44. }
  45. delay(100);
  46. }