49 lines
1.2 KiB
C++
Executable File
49 lines
1.2 KiB
C++
Executable File
#include <RCSwitch.h>
|
|
|
|
RCSwitch mySwitch = RCSwitch();
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
// Transmitter is connected to Arduino Pin #9
|
|
mySwitch.enableTransmit(9);
|
|
|
|
// Set Protocol (default is 1, will work for most outlets)
|
|
//mySwitch.setProtocol(1);
|
|
|
|
// Set pulse length
|
|
// NB Pulse length must be set AFTER Protocol,
|
|
// because setProtocol(1) also sets pulse length = 350
|
|
//mySwitch.setPulseLength(232);
|
|
|
|
// Optional set number of transmission repetitions.
|
|
// Mine seem to work with 2, yours may need more
|
|
//mySwitch.setRepeatTransmit(2);
|
|
}
|
|
|
|
// Switch channel 8 on and off every 1 second
|
|
void loop() {
|
|
command(8, 1);
|
|
delay(1000);
|
|
command(8, 0);
|
|
delay(1000);
|
|
}
|
|
|
|
void command(int nAddress, int nData) {
|
|
|
|
// List of device addresses - may be different for your devices
|
|
char* addressCodes[8] = { "01110000", "00110000", "01010000", "00010000", "01100000", "00100000", "01000000", "00000000" };
|
|
|
|
// List of commands - may be different for your devices
|
|
char* dataCodes[2] = { "0000", "1000" };
|
|
|
|
// Concatenate the Address and Data codes into a single codeword
|
|
char sendCode[13] = "";
|
|
strcat(sendCode, addressCodes[nAddress-1]);
|
|
strcat(sendCode, dataCodes[nData]);
|
|
|
|
// Send the code
|
|
mySwitch.sendTriState(sendCode);
|
|
}
|