* Uses NewRemodeCode::on, ::off, ::dim, ::on_with_dim instead of 0, 1, 2 and 3, for better readability. This change is backwards compatible.
* Updated examples to use the new NewRemodeCode::on, ::off, ::dim and ::on_with_dim notation.
This commit is contained in:
@@ -67,14 +67,18 @@ void showNewCode(NewRemoteCode receivedCode) {
|
||||
}
|
||||
|
||||
switch (receivedCode.switchType) {
|
||||
case 0:
|
||||
case NewRemoteCode::off:
|
||||
Serial.print(" off");
|
||||
break;
|
||||
case 1:
|
||||
case NewRemoteCode::on:
|
||||
Serial.print(" on");
|
||||
break;
|
||||
case 2:
|
||||
Serial.print(" dim level");
|
||||
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;
|
||||
}
|
||||
@@ -102,4 +106,4 @@ void showTempHumi(byte *data) {
|
||||
Serial.print('.');
|
||||
Serial.println(temp % 10); // decimal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ but with slightly different timings, as measured on my device.)
|
||||
_ _
|
||||
dim: | |_| |_ (T,T,T,T)
|
||||
|
||||
T = short period of ~260µs. However, this code tries
|
||||
T = short period of ~260µs. However, this code tries
|
||||
to figure out the correct period
|
||||
|
||||
A full frame looks like this:
|
||||
@@ -111,8 +111,8 @@ void NewRemoteReceiver::interruptHandler() {
|
||||
if (_state == -1) {
|
||||
// wait for the long low part of a stop bit.
|
||||
// Stopbit: 1T high, 40T low
|
||||
// By default 1T is 260us, but for maximum compatiblity go as low as 120us
|
||||
if (duration > 4800) { // =40*120us, minimal time between two edges before decoding starts.
|
||||
// By default 1T is 260µs, but for maximum compatibility go as low as 120µs
|
||||
if (duration > 4800) { // =40*120µs, minimal time between two edges before decoding starts.
|
||||
// Sync signal received.. Preparing for decoding
|
||||
repeats = 0;
|
||||
|
||||
@@ -156,7 +156,20 @@ void NewRemoteReceiver::interruptHandler() {
|
||||
// if first part op stopbit was a short signal (short signal yielded a 0 as second bit in receivedBit), and ...
|
||||
((receivedBit & B10) == B00) &&
|
||||
// we are in a state in which a stopbit is actually valid, only then ...
|
||||
(_state == 147 || _state == 131) ) {
|
||||
(_state == 147 || _state == 131) ) {
|
||||
// If a dim-level was present...
|
||||
if (_state == 147) {
|
||||
// ... test if it was an "on" signal ...
|
||||
if (receivedCode.switchType == NewRemoteCode::on) {
|
||||
// ... set the appropriate switch type
|
||||
receivedCode.switchType = NewRemoteCode::on_with_dim;
|
||||
} else {
|
||||
// ... otherwise it was wrong (e.g. off-signal with dim)
|
||||
_state = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// a valid signal was found!
|
||||
if (
|
||||
receivedCode.address != previousCode.address ||
|
||||
@@ -233,13 +246,13 @@ void NewRemoteReceiver::interruptHandler() {
|
||||
// States 110 - 113 are switch bit states.
|
||||
switch (receivedBit & B1111) {
|
||||
case B0001: // Bit "0" received.
|
||||
receivedCode.switchType = 0;
|
||||
receivedCode.switchType = NewRemoteCode::off;
|
||||
break;
|
||||
case B0100: // Bit "1" received.
|
||||
receivedCode.switchType = 1;
|
||||
case B0100: // Bit "1" received. Note: this might turn out to be a on_with_dim signal.
|
||||
receivedCode.switchType = NewRemoteCode::on;
|
||||
break;
|
||||
case B0000: // Bit "dim" receivd.
|
||||
receivedCode.switchType = 2;
|
||||
case B0000: // Bit "dim" received.
|
||||
receivedCode.switchType = NewRemoteCode::dim;
|
||||
break;
|
||||
default: // Bit was invalid. Abort.
|
||||
_state = -1;
|
||||
@@ -275,7 +288,7 @@ void NewRemoteReceiver::interruptHandler() {
|
||||
case B0001: // Bit "0" received.
|
||||
// receivedCode.dimLevel |= 0; But let's not do that, as it is wasteful.
|
||||
break;
|
||||
case B0100: // Bit "1" receivd.
|
||||
case B0100: // Bit "1" received.
|
||||
receivedCode.dimLevel |= 1;
|
||||
break;
|
||||
default: // Bit was invalid. Abort.
|
||||
|
||||
@@ -10,10 +10,17 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
struct NewRemoteCode {
|
||||
enum SwitchType : unsigned short {
|
||||
off = 0,
|
||||
on = 1,
|
||||
dim = 2,
|
||||
on_with_dim = 3
|
||||
};
|
||||
|
||||
unsigned int period; // Detected duration in microseconds of 1T in the received signal
|
||||
unsigned long address; // Address of received code. [0..2^26-1]
|
||||
boolean groupBit; // Group bit set or not
|
||||
unsigned short switchType; // 0: swich off; 1: switch on; 2: set dim level
|
||||
SwitchType switchType; // off, on, dim, on_with_dim.
|
||||
unsigned short unit; // Unit code of received code [0..15]
|
||||
unsigned short dimLevel; // Dim level [0..15] iff switchType == 2
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@ used by some common "new style" 433MHz remote control switches.
|
||||
There are two styles of remote:
|
||||
- "old style", which uses switches or a dial to set the house code. Use the
|
||||
RemoteSwitch library instead.
|
||||
- "new style", which use a button on the receivers to "learn" a signal. Use this
|
||||
library.
|
||||
- "new style", which use a button on the receivers to "learn" a signal. Use
|
||||
this library.
|
||||
|
||||
License: GPLv3. See ./NewRemoteSwitch/license.txt
|
||||
|
||||
@@ -33,10 +33,14 @@ Default installation demo:
|
||||
|
||||
Changelog:
|
||||
NewRemoteSwitch library v1.1.0 (BETA) for Arduino 1.0
|
||||
- BUGFIX: in many occassions, when receiving a dim-level, the code was rejected
|
||||
- BUGFIX: in many occasions, when receiving a dim-level, the code was rejected
|
||||
even if the signal was correct.
|
||||
- Support decoding A-series transmitters which transmit a dim-level in combination
|
||||
with an on-signal, instead of a dim-signal.
|
||||
- Support decoding A-series transmitters which transmit a dim-level in
|
||||
combination with an on-signal, instead of a dim-signal.
|
||||
- Uses NewRemodeCode::on, ::off, ::dim, ::on_with_dim instead of 0, 1, 2 and 3,
|
||||
for better readability. This change is backwards compatible.
|
||||
- Updated examples to use the new NewRemodeCode::on, ::off, ::dim and
|
||||
::on_with_dim notation.
|
||||
|
||||
NewRemoteSwitch library v1.0.0 (20121229) for Arduino 1.0
|
||||
- Support for receiving A-series Klik-aan-klik-uit remote. (NewRemoteReceiver)
|
||||
|
||||
@@ -51,13 +51,14 @@ void processCode(NewRemoteCode receivedCode) {
|
||||
// Yes!
|
||||
// Is the received code identical to the learned code?
|
||||
if (receivedCode.address == learnedAddress && receivedCode.unit == learnedUnit) {
|
||||
// Yes!
|
||||
// switchType == 1 means on, switchType == 0 means off.
|
||||
if (receivedCode.switchType == 1) {
|
||||
digitalWrite(13, HIGH);
|
||||
} else if (receivedCode.switchType == 0) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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,
|
||||
* When run, this sketch waits for a valid code from a new-style the receiver,
|
||||
* decodes it, and retransmits it after 5 seconds.
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ void setup() {
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void retransmitter(NewRemoteCode receivedCode) {
|
||||
void retransmitter(NewRemoteCode receivedCode) {
|
||||
// Disable the receiver; otherwise it might pick up the retransmit as well.
|
||||
NewRemoteReceiver::disable();
|
||||
|
||||
@@ -33,24 +33,24 @@ void retransmitter(NewRemoteCode receivedCode) {
|
||||
|
||||
NewRemoteTransmitter transmitter(receivedCode.address, 11, receivedCode.period);
|
||||
|
||||
// Switch type 0 = switch off, type 1 = switch on, type 2 = set dim level.
|
||||
if (receivedCode.switchType == 2) {
|
||||
if (receivedCode.switchType == NewReceiverCode::dim) {
|
||||
// Dimmer signal received
|
||||
transmitter.sendDim(receivedCode.unit, receivedCode.dimLevel);
|
||||
}
|
||||
transmitter.sendDim(receivedCode.unit, receivedCode.dimLevel);
|
||||
}
|
||||
else {
|
||||
// On/Off signal received
|
||||
bool isOn == receivedCode.switchType == NewReceiverCode::on || receivedCode.switchType == NewReceiverCode::on_with_dim
|
||||
|
||||
if (receivedCode.groupBit) {
|
||||
// Send to the group
|
||||
transmitter.sendGroup(receivedCode.switchType);
|
||||
}
|
||||
transmitter.sendGroup(isOn);
|
||||
}
|
||||
else {
|
||||
// Send to a single unit
|
||||
transmitter.sendUnit(receivedCode.unit, receivedCode.switchType);
|
||||
transmitter.sendUnit(receivedCode.unit, isOn);
|
||||
}
|
||||
}
|
||||
|
||||
NewRemoteReceiver::enable();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,14 +41,18 @@ void showCode(NewRemoteCode receivedCode) {
|
||||
}
|
||||
|
||||
switch (receivedCode.switchType) {
|
||||
case 0:
|
||||
case NewRemoteCode::off:
|
||||
Serial.print(" off");
|
||||
break;
|
||||
case 1:
|
||||
case NewRemoteCode::on:
|
||||
Serial.print(" on");
|
||||
break;
|
||||
case 2:
|
||||
Serial.print(" dim level");
|
||||
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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ QUICKSTART:
|
||||
ReceiveRemoteAndSensor.
|
||||
* Connect a 433MHz receiver to digital pin 2 on the Arduino.
|
||||
* Run the sketch.
|
||||
* Enabled the serial monitor at 1152 baud.
|
||||
* Enabled the serial monitor at 115200 baud.
|
||||
* Press buttons on your remote(s), and/or wait for your thermo/hygro sensor
|
||||
to transmit.
|
||||
* You should see the received data in the serial monitor.
|
||||
Reference in New Issue
Block a user