Add pubsub client
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Demo for RF remote switch transmitter.
|
||||
* For details, see RemoteTransmitter.h!
|
||||
*
|
||||
* This sketch switches some devices on and off in a loop.
|
||||
*
|
||||
* Setup:
|
||||
* - Connect a 433MHz transmitter to digital pin 11.
|
||||
*/
|
||||
|
||||
#include <RemoteTransmitter.h>
|
||||
|
||||
// Intantiate a new ActionTransmitter remote, use pin 11
|
||||
ActionTransmitter actionTransmitter(11);
|
||||
|
||||
// Intantiate a new KaKuTransmitter remote, also use pin 11 (same transmitter!)
|
||||
KaKuTransmitter kaKuTransmitter(11);
|
||||
|
||||
// Intantiate a new Blokker remote, also use pin 11 (same transmitter!)
|
||||
BlokkerTransmitter blokkerTransmitter(11);
|
||||
|
||||
// Intantiate a new Elro remote, also use pin 11 (same transmitter!)
|
||||
ElroTransmitter elroTransmitter(11);
|
||||
|
||||
|
||||
void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Switch off KaKu-device 10 on address M
|
||||
kaKuTransmitter.sendSignal('M',10,false);
|
||||
|
||||
// Switch on Action-device B on system code 1.
|
||||
actionTransmitter.sendSignal(1,'B',true);
|
||||
|
||||
// Switch on Blokker-device 7.
|
||||
blokkerTransmitter.sendSignal(7,true);
|
||||
|
||||
// Switch on Elro-device C on system code 1.
|
||||
elroTransmitter.sendSignal(1,'C',true);
|
||||
|
||||
|
||||
// Wait 2 seconds
|
||||
delay(2000);
|
||||
|
||||
|
||||
|
||||
// Switch on KaKu-device 2 of group 3 on address M (which is the same as device 10 on address M!)
|
||||
kaKuTransmitter.sendSignal('M',3,2,true);
|
||||
|
||||
// Switch off Action-device B on system code 1.
|
||||
actionTransmitter.sendSignal(1,'B',false);
|
||||
|
||||
// Switch off Blokker-device 7.
|
||||
blokkerTransmitter.sendSignal(7,false);
|
||||
|
||||
// Switch off Elro-device C on system code 1.
|
||||
elroTransmitter.sendSignal(1,'C',false);
|
||||
|
||||
|
||||
// Wait 4 seconds
|
||||
delay(4000);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Demo for RF remote switch receiver.
|
||||
* For details, see RemoteReceiver.h!
|
||||
*
|
||||
* This sketch "translates" an Action-remote to a Blokker-remote.
|
||||
* When the A-On-button of the Action-remote is pressed, the Blokker-devices
|
||||
* 5, 6 and 7 are switched on. The A-Off-button switches the devices off again.
|
||||
*
|
||||
* Connect the transmitter to digital pin 11, and the receiver to digital pin 2.
|
||||
*/
|
||||
|
||||
#include <RemoteReceiver.h>
|
||||
#include <RemoteTransmitter.h>
|
||||
|
||||
ActionTransmitter actionTransmitter(11);
|
||||
BlokkerTransmitter blokkerTransmitter(11);
|
||||
|
||||
// Prepare the code for switch A (system code 1) on and off, for easy comparision later.
|
||||
unsigned long actionAOn = actionTransmitter.getTelegram(1,'A',true);
|
||||
unsigned long actionAOff = actionTransmitter.getTelegram(1,'A',false);
|
||||
|
||||
void setup() {
|
||||
// See example Show_received_code for info on this
|
||||
RemoteReceiver::init(0, 3, translateCode);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
// Callback function is called only when a valid code is received.
|
||||
void translateCode(unsigned long receivedCode, unsigned int period) {
|
||||
// Enabled interrupts, so RemoteReceiver::isReceiving() can be used.
|
||||
interrupts();
|
||||
|
||||
// Compare the signals
|
||||
if (RemoteTransmitter::isSameCode(actionAOn, receivedCode)) {
|
||||
// A-On-button pressed!
|
||||
|
||||
// Wait for a free ether
|
||||
while(RemoteReceiver::isReceiving());
|
||||
|
||||
// Switch devices on
|
||||
blokkerTransmitter.sendSignal(5,true);
|
||||
blokkerTransmitter.sendSignal(6,true);
|
||||
blokkerTransmitter.sendSignal(7,true);
|
||||
|
||||
} else if (RemoteTransmitter::isSameCode(actionAOff, receivedCode)) {
|
||||
// A-Off-button pressed!
|
||||
|
||||
// Wait for a free ether
|
||||
while(RemoteReceiver::isReceiving());
|
||||
|
||||
// Switch devices off
|
||||
blokkerTransmitter.sendSignal(5,false);
|
||||
blokkerTransmitter.sendSignal(6,false);
|
||||
blokkerTransmitter.sendSignal(7,false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Demo for RF remote switch receiver.
|
||||
* For details, see RemoteReceiver.h!
|
||||
*
|
||||
* This sketch demonstrates how to use the static version of
|
||||
* RemoteReceiver::sendCode, which can be used in low-memory
|
||||
* situations.
|
||||
*
|
||||
* Connect the transmitter to digital pin 11, and the receiver to digital pin 2.
|
||||
*
|
||||
* When run, this sketch waits for a valid code from the receiver, decodes it,
|
||||
* and retransmits it after 5 seconds.
|
||||
*/
|
||||
|
||||
#include <RemoteReceiver.h>
|
||||
#include <RemoteTransmitter.h>
|
||||
|
||||
void setup() {
|
||||
// See example Show_received_code for info on this
|
||||
RemoteReceiver::init(0, 3, retransmitter);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void retransmitter(unsigned long receivedCode, unsigned int period) {
|
||||
// Disable the receiver; otherwise it might pick up the retransmit as well.
|
||||
RemoteReceiver::disable();
|
||||
|
||||
// Need interrupts for delay()
|
||||
interrupts();
|
||||
|
||||
// Wait 5 seconds before sending.
|
||||
delay(5000);
|
||||
|
||||
// Retransmit the signal 8 times ( == 2^3) on pin 11. Note: no object was created!
|
||||
RemoteTransmitter::sendCode(11, receivedCode, period, 3);
|
||||
|
||||
RemoteReceiver::enable();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Demo for RF remote switch receiver.
|
||||
* For details, see RemoteReceiver.h!
|
||||
*
|
||||
* This sketch shows the received signals on the serial port.
|
||||
* Connect the receiver to digital pin 2.
|
||||
*/
|
||||
|
||||
#include <RemoteReceiver.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize receiver on interrupt 0 (= digital pin 2), calls the callback "showCode"
|
||||
// after 3 identical codes have been received in a row. (thus, keep the button pressed
|
||||
// for a moment)
|
||||
//
|
||||
// See the interrupt-parameter of attachInterrupt for possible values (and pins)
|
||||
// to connect the receiver.
|
||||
RemoteReceiver::init(0, 3, showCode);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
// Callback function is called only when a valid code is received.
|
||||
void showCode(unsigned long receivedCode, unsigned int period) {
|
||||
// Note: interrupts are disabled. You can re-enable them if needed.
|
||||
|
||||
// Print the received code.
|
||||
Serial.print("Code: ");
|
||||
Serial.print(receivedCode);
|
||||
Serial.print(", period duration: ");
|
||||
Serial.print(period);
|
||||
Serial.println("us.");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user