Lightweight Arduino IR library for normal NEC protocol remote control devices.
If you have one of these cheap remote control units, with a matching IR receiver, you may find this library useful. It is specifically designed for the NEC IR protocol. Unlike the standard IR library, it does not use a timer and instead uses external interrupts. Its design based on a state machine model.
When compiled for a Uno, it uses 214 bytes of global variables and 3356 bytes of program storage space which is about half of the storage requirements of the more comprehensive standard Arduino IR library.
I've tested it on a Uno, an ATtiny841 (8 MHz internal) and a NodeMCU ESP8266. With the AVR processors, you are restricted on which pins you can use because of the external interrupts. If you cannot use an external interrupt pin, it should, however, not be too difficult to modify the code to use pin change interrupts instead.
There is a description of the NEC protocol here: NEC IR Remote Control Interface with 8051 - Tutorials or a more comprehensive one including extended codes and repeat https://www.ad-notam.com/download/RS232/ad_notam_IR_protocol_DFU.pdf
I've attached a sample demonstration sketch and the 2 parts of the library ( IrNec.cpp and IrNec.h) which can be added to the sketch folder.
Edit 1 : IrNec.cpp and IrNec.h updated to support repeat code (0xFFFFFFFF) and IR code byte order corrected.
AT841_IR_v0_01.ino (1.01 KB)
IrNec.h (1.04 KB)
IrNec.cpp (3.74 KB)
