Infrared library for remote controls using the NEC protocol
BSD licensed infrared receiver library for ATMega and ATTiny / AVR-GCC
Since I couldn't find any code with a suitable license on the internet, I wrote my own function library. The implementation needs an interrupt and a 8-bit timer and works on an ATMega48, ATMega88, ATMega168, ATMega328 as well as ATTiny2313 and ATTiny4313.
In the interrupt a state machine is used to decode the signal. The signal is completely analyzed and checked for errors. It can also be read out if the user is holding the button down. The library is used in several kits and projects I developed.
Using the library
The corresponding timer and interrupt settings are initialized with the following call:
Now the last received packet is available in a struct ir_struct, which can be retrieved in the global variable ir. This contains address, command and a status flag. The bit IR_RECIEVED of the flag is set when a valid packet was received and must be reset in the main program after processing. As long as the key is held, the bit IR_KEYHOLD is set.
The processing could look like this:
If no more reception is required, the interrupts can be stopped again by the following call:
- IR Remote Control, NEC Protocol Description
- A Multi-Protocol Infrared Remote Library for the Arduino