Move master branch from from mios git repo

This commit is contained in:
hek
2014-01-23 00:23:15 +01:00
commit 609d9e5be9
352 changed files with 53418 additions and 0 deletions
@@ -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,53 @@
/*
* 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) {
// Dimmer signal received
transmitter.sendDim(receivedCode.unit, receivedCode.dimLevel);
} else {
// On/Off signal received
bool isOn = receivedCode.switchType == NewRemoteCode::on || receivedCode.switchType == NewRemoteCode::on_with_dim;
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,65 @@
/*
* Demo for RF remote switch receiver.
* This example is for the new KaKu / Home Easy type of remotes!
* For details, see NewRemoteReceiver.h!
*
* This sketch shows the received signals on the serial port.
* Connect the receiver to digital pin 2.
*/
#include <NewRemoteReceiver.h>
void setup() {
Serial.begin(115200);
// Initialize receiver on interrupt 0 (= digital pin 2), calls the callback "showCode"
// after 2 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.
NewRemoteReceiver::init(0, 2, showCode);
}
void loop() {
}
// Callback function is called only when a valid code is received.
void showCode(NewRemoteCode receivedCode) {
// Note: interrupts are disabled. You can re-enable them if needed.
// Print the received code.
Serial.print("Addr ");
Serial.print(receivedCode.address);
if (receivedCode.groupBit) {
Serial.print(" group");
} else {
Serial.print(" unit ");
Serial.print(receivedCode.unit);
}
switch (receivedCode.switchType) {
case NewRemoteCode::off:
Serial.print(" off");
break;
case NewRemoteCode::on:
Serial.print(" on");
break;
case NewRemoteCode::dim:
Serial.print(" dim level ");
Serial.print(receivedCode.dimLevel);
break;
case NewRemoteCode::on_with_dim:
Serial.print(" on with dim level ");
Serial.print(receivedCode.dimLevel);
break;
}
Serial.print(", period: ");
Serial.print(receivedCode.period);
Serial.println("us.");
}