ShowReceivedCode.ino 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Demo for RF remote switch receiver.
  3. * For details, see RemoteReceiver.h!
  4. *
  5. * This sketch shows the received signals on the serial port.
  6. * Connect the receiver to digital pin 2 on arduino and digital pin 1 on ESP8266.
  7. * Detected codes example:
  8. Code: 8233372 Period: 273
  9. unit: 1
  10. groupBit: 0
  11. switchType: 0
  12. */
  13. #include <NewRemoteReceiver.h>
  14. void setup() {
  15. Serial.begin(115200);
  16. // Initialize receiver on interrupt 0 (= digital pin 2) for arduino uno, calls the callback "showCode"
  17. // after 1 identical codes have been received in a row. (thus, keep the button pressed
  18. // for a moment), on esp8266 use on interrupt 5 = digital pin 1
  19. //
  20. // See the interrupt-parameter of attachInterrupt for possible values (and pins)
  21. // to connect the receiver.
  22. // if you don't see codes try to reset your board after upload
  23. #ifdef ESP8266
  24. NewRemoteReceiver::init(5, 2, showCode);
  25. #else
  26. NewRemoteReceiver::init(0, 2, showCode);
  27. #endif
  28. Serial.println("Receiver initialized");
  29. }
  30. void loop() {
  31. }
  32. // Callback function is called only when a valid code is received.
  33. void showCode(unsigned int period, unsigned long address, unsigned long groupBit, unsigned long unit, unsigned long switchType) {
  34. // Print the received code.
  35. Serial.print("Code: ");
  36. Serial.print(address);
  37. Serial.print(" Period: ");
  38. Serial.println(period);
  39. Serial.print(" unit: ");
  40. Serial.println(unit);
  41. Serial.print(" groupBit: ");
  42. Serial.println(groupBit);
  43. Serial.print(" switchType: ");
  44. Serial.println(switchType);
  45. }