publish libraries to avoid users to have to download them one by one
This commit is contained in:
1 parent
93c075e880
commit
f0546fab8c
396 files changed
+536928
No files matched your search
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Demo for RF remote switch receiver.
|
||||
* This example is for the new KaKu / Home Easy type of remotes!
|
||||
*
|
||||
* For details, see NewRemoteReceiver.h!
|
||||
*
|
||||
* With this sketch you can control a LED connected to digital pin 13,
|
||||
* after the sketch learned the code. After start, the LED starts to blink,
|
||||
* until a valid code has been received. The led stops blinking. Now you
|
||||
* can control the LED with the remote.
|
||||
*
|
||||
* Note: only unit-switches are supported in this sketch, no group or dim.
|
||||
*
|
||||
* Set-up: connect the receiver to digital pin 2 and a LED to digital pin 13.
|
||||
*/
|
||||
|
||||
#include <NewRemoteReceiver.h>
|
||||
|
||||
boolean codeLearned = false;
|
||||
unsigned long learnedAddress;
|
||||
byte learnedUnit;
|
||||
|
||||
void setup() {
|
||||
// LED-pin as output
|
||||
pinMode(13, OUTPUT);
|
||||
|
||||
// Init a new receiver on interrupt pin 0, minimal 2 identical repeats, and callback set to processCode.
|
||||
NewRemoteReceiver::init(0, 2, processCode);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Blink led until a code has been learned
|
||||
if (!codeLearned) {
|
||||
digitalWrite(13, HIGH);
|
||||
delay(500);
|
||||
digitalWrite(13, LOW);
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
// Callback function is called only when a valid code is received.
|
||||
void processCode(NewRemoteCode receivedCode) {
|
||||
// A code has been received.
|
||||
// Do we already know the code?
|
||||
if (!codeLearned) {
|
||||
// No! Let's learn the received code.
|
||||
learnedAddress = receivedCode.address;
|
||||
learnedUnit = receivedCode.unit;
|
||||
codeLearned = true;
|
||||
} else {
|
||||
// Yes!
|
||||
// Is the received code identical to the learned code?
|
||||
if (receivedCode.address == learnedAddress && receivedCode.unit == learnedUnit) {
|
||||
// Yes!
|
||||
// Switch the LED off if the received code was "off".
|
||||
// Anything else (on, dim, on_with_dim) will switch the LED on.
|
||||
if (receivedCode.switchType == NewRemoteCode::off) {
|
||||
digitalWrite(13, LOW);
|
||||
} else {
|
||||
digitalWrite(13, HIGH);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Demo for RF remote switch receiver.
|
||||
* For details, see NewRemoteReceiver.h!
|
||||
*
|
||||
* Connect the transmitter to digital pin 11.
|
||||
*
|
||||
* This sketch demonstrates the use of the NewRemoteTransmitter class.
|
||||
*
|
||||
* When run, this sketch switches some pre-defined devices on and off in a loop.
|
||||
*
|
||||
* NOTE: the actual receivers have the address and group numbers in this example
|
||||
* are only for demonstration! If you want to duplicate an existing remote, please
|
||||
* try the "retransmitter"-example instead.
|
||||
*
|
||||
* To use this actual example, you'd need to "learn" the used code in the receivers
|
||||
* This sketch is unsuited for that.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <NewRemoteTransmitter.h>
|
||||
|
||||
// Create a transmitter on address 123, using digital pin 11 to transmit,
|
||||
// with a period duration of 260ms (default), repeating the transmitted
|
||||
// code 2^3=8 times.
|
||||
NewRemoteTransmitter transmitter(123, 11, 260, 3);
|
||||
|
||||
void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Switch unit 2 off
|
||||
transmitter.sendUnit(2, false);
|
||||
|
||||
// Switch all devices in the group off
|
||||
transmitter.sendGroup(false);
|
||||
|
||||
// Set unit 1 to dim-level 3 (range 0-15)
|
||||
transmitter.sendDim(1, 3);
|
||||
|
||||
// Wait 5 seconds
|
||||
delay(5000);
|
||||
|
||||
|
||||
// Switch unit 2 on
|
||||
transmitter.sendUnit(2, true);
|
||||
|
||||
// Switch all devices in the group on
|
||||
transmitter.sendGroup(true);
|
||||
|
||||
// Set unit 1 to dim-level 15, full brightness.
|
||||
transmitter.sendDim(1, 15);
|
||||
|
||||
// Wait 5 seconds
|
||||
delay(5000);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Demo for RF remote switch receiver.
|
||||
* For details, see NewRemoteReceiver.h!
|
||||
*
|
||||
* Connect the transmitter to digital pin 11, and the receiver to digital pin 2.
|
||||
*
|
||||
* When run, this sketch waits for a valid code from a new-style the receiver,
|
||||
* decodes it, and retransmits it after 5 seconds.
|
||||
*/
|
||||
|
||||
#include <NewRemoteReceiver.h>
|
||||
#include <NewRemoteTransmitter.h>
|
||||
|
||||
void setup() {
|
||||
// See example ShowReceivedCode for info on this
|
||||
NewRemoteReceiver::init(0, 2, retransmitter);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void retransmitter(NewRemoteCode receivedCode) {
|
||||
// Disable the receiver; otherwise it might pick up the retransmit as well.
|
||||
NewRemoteReceiver::disable();
|
||||
|
||||
// Need interrupts for delay()
|
||||
interrupts();
|
||||
|
||||
// Wait 5 seconds before sending.
|
||||
delay(5000);
|
||||
|
||||
// Create a new transmitter with the received address and period, use digital pin 11 as output pin
|
||||
|
||||
NewRemoteTransmitter transmitter(receivedCode.address, 11, receivedCode.period);
|
||||
|
||||
if (receivedCode.switchType == NewRemoteCode::dim ||
|
||||
(receivedCode.switchType == NewRemoteCode::on && receivedCode.dimLevelPresent)) {
|
||||
// Dimmer signal received
|
||||
|
||||
if (receivedCode.groupBit) {
|
||||
transmitter.sendGroupDim(receivedCode.dimLevel);
|
||||
}
|
||||
else {
|
||||
transmitter.sendDim(receivedCode.unit, receivedCode.dimLevel);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// On/Off signal received
|
||||
bool isOn = receivedCode.switchType == NewRemoteCode::on;
|
||||
|
||||
if (receivedCode.groupBit) {
|
||||
// Send to the group
|
||||
transmitter.sendGroup(isOn);
|
||||
}
|
||||
else {
|
||||
// Send to a single unit
|
||||
transmitter.sendUnit(receivedCode.unit, isOn);
|
||||
}
|
||||
}
|
||||
|
||||
NewRemoteReceiver::enable();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 on arduino and digital pin 1 on ESP8266.
|
||||
* Detected codes example:
|
||||
Code: 8233372 Period: 273
|
||||
unit: 1
|
||||
groupBit: 0
|
||||
switchType: 0
|
||||
*/
|
||||
|
||||
#include <NewRemoteReceiver.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// Initialize receiver on interrupt 0 (= digital pin 2) for arduino uno, calls the callback "showCode"
|
||||
// after 1 identical codes have been received in a row. (thus, keep the button pressed
|
||||
// for a moment), on esp8266 use on interrupt 5 = digital pin 1
|
||||
//
|
||||
// See the interrupt-parameter of attachInterrupt for possible values (and pins)
|
||||
// to connect the receiver.
|
||||
|
||||
// if you don't see codes try to reset your board after upload
|
||||
|
||||
#ifdef ESP8266
|
||||
NewRemoteReceiver::init(5, 2, showCode);
|
||||
#else
|
||||
NewRemoteReceiver::init(0, 2, showCode);
|
||||
#endif
|
||||
Serial.println("Receiver initialized");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
// Callback function is called only when a valid code is received.
|
||||
void showCode(unsigned int period, unsigned long address, unsigned long groupBit, unsigned long unit, unsigned long switchType) {
|
||||
|
||||
// Print the received code.
|
||||
Serial.print("Code: ");
|
||||
Serial.print(address);
|
||||
Serial.print(" Period: ");
|
||||
Serial.println(period);
|
||||
Serial.print(" unit: ");
|
||||
Serial.println(unit);
|
||||
Serial.print(" groupBit: ");
|
||||
Serial.println(groupBit);
|
||||
Serial.print(" switchType: ");
|
||||
Serial.println(switchType);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user