NewRemoteTransmitter.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * NewRemoteSwitch library v1.2.0 (20140128) made by Randy Simons http://randysimons.nl/
  3. *
  4. * License: GPLv3. See license.txt
  5. */
  6. #ifndef NewRemoteTransmitter_h
  7. #define NewRemoteTransmitter_h
  8. #include <Arduino.h>
  9. /**
  10. * NewRemoteTransmitter provides a generic class for simulation of common RF remote controls, like the A-series
  11. * 'Klik aan Klik uit'-system (http://www.klikaanklikuit.nl/), used to remotely switch lights etc.
  12. *
  13. * This class is meant for new-style remotes, usually accompanied by receivers with "code learning"
  14. * capabilities. For other remotes, use the RemoteTransmitter class.
  15. *
  16. * Hardware required for this library: a 433MHz/434MHz SAW oscillator transmitter, e.g.
  17. * http://www.sparkfun.com/products/10534
  18. * http://www.conrad.nl/goto/?product=130428
  19. *
  20. * Notes:
  21. * - I measured the period length with an oscilloscope, using a A-series KAKU transmitter. Other devices
  22. * or manufacturers may use other period length. Use the ShowReceivedCodeNewRemote example to find the
  23. * period length for your devices.
  24. * - You can copy the address of your "real" remotes, so you won't have to learn new codes into the receivers.
  25. * In effect this duplicates a remote. But you can also pick a random number in the range 0..2^26-1.
  26. */
  27. class NewRemoteTransmitter {
  28. public:
  29. /**
  30. * Constructor.
  31. *
  32. * To obtain the correct period length, use the ShowReceivedCodeNewRemote example, or you
  33. * can use an oscilloscope.
  34. *
  35. * @param address Address of this transmitter [0..2^26-1] Duplicate the address of your hardware, or choose a random number.
  36. * @param pin Output pin on Arduino to which the transmitter is connected
  37. * @param periodusec Duration of one period, in microseconds. One bit takes 8 periods (but only 4 for 'dim' signal).
  38. * @param repeats [0..8] The 2log-Number of times the signal is repeated. The actual number of repeats will be 2^repeats. 2 would be bare minimum, 4 seems robust, 8 is maximum (and overkill).
  39. */
  40. NewRemoteTransmitter(unsigned long address, byte pin, unsigned int periodusec = 260, byte repeats = 4);
  41. /**
  42. * Send on/off command to the address group.
  43. *
  44. * @param switchOn True to send "on" signal, false to send "off" signal.
  45. */
  46. void sendGroup(boolean switchOn);
  47. /**
  48. * Send on/off command to an unit on the current address.
  49. *
  50. * @param unit [0..15] target unit.
  51. * @param switchOn True to send "on" signal, false to send "off" signal.
  52. */
  53. void sendUnit(byte unit, boolean switchOn);
  54. /**
  55. * Send dim value to an unit on the current address. This will also switch on the device.
  56. * Note that low bound can be limited on the dimmer itself. Setting a dimLevel of 0
  57. * may not actually turn off the device.
  58. *
  59. * @param unit [0..15] target unit.
  60. * @param dimLevel [0..15] Dim level. 0 for off, 15 for brightest level.
  61. */
  62. void sendDim(byte unit, byte dimLevel);
  63. /**
  64. * Send dim value the current address group. This will also switch on the device.
  65. * Note that low bound can be limited on the dimmer itself. Setting a dimLevel of 0
  66. * may not actually turn off the device.
  67. *
  68. * @param dimLevel [0..15] Dim level. 0 for off, 15 for brightest level.
  69. */
  70. void sendGroupDim(byte dimLevel);
  71. protected:
  72. unsigned long _address; // Address of this transmitter.
  73. byte _pin; // Transmitter output pin
  74. unsigned int _periodusec; // Oscillator period in microseconds
  75. byte _repeats; // Number over repetitions of one telegram
  76. /**
  77. * Transmits start-pulse
  78. */
  79. void _sendStartPulse();
  80. /**
  81. * Transmits address part
  82. */
  83. void _sendAddress();
  84. /**
  85. * Transmits unit part.
  86. *
  87. * @param unit [0-15] target unit.
  88. */
  89. void _sendUnit(byte unit);
  90. /**
  91. * Transmits stop pulse.
  92. */
  93. void _sendStopPulse();
  94. /**
  95. * Transmits a single bit.
  96. *
  97. * @param isBitOne True, to send '1', false to send '0'.
  98. */
  99. void _sendBit(boolean isBitOne);
  100. };
  101. #endif