Skip to content

Commit 105e6fb

Browse files
committed
Fix send NEC 16 bit address bug. Improved SendDemo example for #760
1 parent fac0190 commit 105e6fb

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ This is a quite old but maybe useful wiki for this library.
3636
- The decoded result is now in in `IrReceiver.decodedIRData` and not in `results` any more, therefore replace any occurrences of `results.value` and / or `results.decode_type` (and similar) to `IrReceiver.decodedIRData.decodedRawData` and / or `IrReceiver.decodedIRData.decodedRawData`.
3737
- Overflow, Repeat and other flags are now in [`IrReceiver.receivedIRData.flags`](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/src/IRremote.h#L126).
3838
- Seldom used: `results.rawbuf` and `results.rawlen` must be replaced by `IrReceiver.decodedIRData.rawDataPtr->rawbuf` and `IrReceiver.decodedIRData.rawDataPtr->rawlen`.
39-
- The old functions `sendNEC()` and `sendJVC()` are deprecated and renamed to `sendNECMSB()` and `sendJVCMSB()` to make it clearer that they send data with MSB first, which is not the standard for NEC and JVC.
40-
They are kept as well as other old send functions to enable usage of **old** 32 bit IR data codes.
39+
- The old functions `sendNEC()` and `sendJVC()` are deprecated and renamed to `sendNECMSB()` and `sendJVCMSB()` to make it clearer that they send data with MSB first, which is not the standard for NEC and JVC. Use them to send your **old 32 bit IR data codes**.
4140
In the new version you will send NEC commands not by 32 bit codes but by a (constant) 8 bit address and an 8 bit command.
4241

4342
# FAQ

examples/IRsendDemo/IRsendDemo.ino

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414

1515
//#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 240 bytes program space if IrSender.write is used
16-
1716
#include <IRremote.h>
1817
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
1918
#include "ATtinySerialOut.h"
@@ -83,10 +82,24 @@ void loop() {
8382
"0017 0806"), 0); //stop bit, no repeat possible, because of missing repeat pattern
8483
delay(2000);
8584

85+
/*
86+
* With sendNECRaw() you can send even "forbidden" codes with parity errors
87+
*/
8688
Serial.println(
8789
F(
88-
"Send NECRaw 0xCC340102 with 16 bit address 0x102 and command 0x34 which results in a parity error, since CC != ~34"));
89-
IrSender.sendNECRaw(0xCC340102, sRepeats);
90+
"Send NEC with 16 bit address 0x0102 and command 0x34 with NECRaw(0xCC340102) which results in a parity error, since 34 == ~CB and not C0"));
91+
IrSender.sendNECRaw(0xC0340102, sRepeats);
92+
delay(2000);
93+
94+
/*
95+
* With Send sendNECMSB() you can send your old 32 bit codes.
96+
* To convert one into the other, you must reverse the byte positions and then reverse all positions of each byte.
97+
* Example:
98+
* 0xCB340102 byte reverse -> 0x020134CB bit reverse-> 40802CD3
99+
*
100+
*/
101+
Serial.println(F("NEC with 16 bit address 0x0102 and command 0x34 with old 32 bit format MSB first"));
102+
IrSender.sendNECMSB(0x40802CD3, 32, false);
90103
delay(2000);
91104
}
92105

src/IRremote.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
*/
8888
#if !defined(MARK_EXCESS_MICROS)
8989
//#define MARK_EXCESS_MICROS 50
90-
#define MARK_EXCESS_MICROS 20 // recommended for the cheap VS1838 modules
90+
#define MARK_EXCESS_MICROS 20 // 20 is recommended for the cheap VS1838 modules
9191
#endif
9292

9393
//------------------------------------------------------------------------------

src/ir_NEC.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ void IRsend::sendNEC(uint16_t aAddress, uint8_t aCommand, uint8_t aNumberOfRepea
9292
// assume 8 bit address -> send 8 address bits and then 8 inverted address bits LSB first
9393
tRawData.UByte.LowByte = aAddress;
9494
tRawData.UByte.MidLowByte = ~tRawData.UByte.LowByte;
95+
} else {
96+
tRawData.UWord.LowWord = aAddress;
9597
}
9698

9799
// send 8 command bits and then 8 inverted command bits LSB first

0 commit comments

Comments
 (0)