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.

58 lines
1.7 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 "translates" a Action-remote to a Blokker-remote.
  8. * When the A-On-button of the Action-remote is pressed, the Blokker-devices
  9. * 5, 6 and 7 are switched on. The A-Off-button switches the devices off again.
  10. *
  11. * Connect the transmitter to digital pin 11, and the receiver to digital pin 2.
  12. */
  13. ActionSwitch actionSwitch(11);
  14. BlokkerSwitch blokkerSwitch(11);
  15. //Prepare the code for switch A (system code 1) on and off, for easy comparision later.
  16. unsigned long actionAOn = actionSwitch.getTelegram(1,'A',true);
  17. unsigned long actionAOff = actionSwitch.getTelegram(1,'A',false);
  18. void setup() {
  19. //See example Show_received_code for info on this
  20. RemoteReceiver::init(0, 3, translateCode);
  21. }
  22. void loop() {
  23. }
  24. //Callback function is called only when a valid code is received.
  25. void translateCode(unsigned long receivedCode, unsigned int period) {
  26. //Enabled interrupts, so RemoteReceiver::isReceiving() can be used.
  27. interrupts();
  28. //Compare the signals
  29. if (RemoteSwitch::isSameCode(actionAOn, receivedCode)) {
  30. //A-On-button pressed!
  31. //Wait for a free ether
  32. while(RemoteReceiver::isReceiving());
  33. //Switch devices on
  34. blokkerSwitch.sendSignal(5,true);
  35. blokkerSwitch.sendSignal(6,true);
  36. blokkerSwitch.sendSignal(7,true);
  37. } else if (RemoteSwitch::isSameCode(actionAOff, receivedCode)) {
  38. //A-Off-button pressed!
  39. //Wait for a free ether
  40. while(RemoteReceiver::isReceiving());
  41. //Switch devices off
  42. blokkerSwitch.sendSignal(5,false);
  43. blokkerSwitch.sendSignal(6,false);
  44. blokkerSwitch.sendSignal(7,false);
  45. }
  46. }