Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

  1. #include <RemoteReceiver.h>
  2. #include <RemoteSwitch.h>
  3. /*
  4. * Demo for RF remote switch receiver.
  5. * For details, see RemoteReceiver.h!
  6. *
  7. * This sketch demonstrates how to use the static version of
  8. * RemoteReceiver::sendTelegram, which can be used in low-memory
  9. * situations.
  10. *
  11. * Connect the transmitter to digital pin 11, and the receiver to digital pin 2.
  12. *
  13. * When run, this sketch waits for a valid code from the receiver, decodes it,
  14. * and retransmits it after 5 seconds.
  15. */
  16. void setup() {
  17. //See example Show_received_code for info on this
  18. RemoteReceiver::init(0, 3, showCode);
  19. }
  20. void loop() {
  21. }
  22. void showCode(unsigned long receivedCode, unsigned int period) {
  23. //Disable the receiver; otherwise it might pick up the retransmit as well.
  24. RemoteReceiver::disable();
  25. //Need interrupts for delay
  26. interrupts();
  27. unsigned long code;
  28. //Copy the received code.
  29. code = receivedCode & 0xFFFFF; //truncate to 20 bits for show; receivedCode is never more than 20 bits..
  30. //Add the period duration to the code. Range: [0..511] (9 bit)
  31. code |= (unsigned long)period << 23;
  32. //Add the number of repeats to the code. Range: [0..7] (3 bit). The actual number of repeats will be 2^(repeats),
  33. //in this case 8
  34. code |= 3L << 20;
  35. //Wait 5 seconds before sending.
  36. delay(5000);
  37. //Retransmit the signal on pin 11. Note: no object was created!
  38. RemoteSwitch::sendTelegram(code,11);
  39. RemoteReceiver::enable();
  40. }