User manual

How It Works
The program creates a receiver on object, a decoder object and a servo object. You can find more
information on the standard Arduino Servo library here (http://adafru.it/ecQ). The setup function
attaches the servo, enables IR input, and initializes several variables.
The loop function gets an IR code and passes it to a switch statement depending on its value. Each
case of the switch statement handles a different function moving the servo as needed.
There is one bit of overhead we need to take care of because we are using NEC protocol. That
protocol has a unique feature that allows you to see if the button on the remote has been held down
to send repeated instances of the same value. It has a special sequence of marks and spaces that
mean "Repeat what you did last time". When IRLib sees the special sequence, it returns the value
0xFFFFFFFF. We take care of that special case by storing the previous value at the bottom of the
switch statement so that if we get a repeat code we can substitute it the next time. NEC protocol is
the only protocol that uses this particular method for detecting repeat codes. Other protocols have
other systems which are explained in detail in the IRLib documentation.
Special Instructions for ATmega32u4 based systems
The example as presented here should work okay on Arduino Uno or Mega however if you are
using Arduino Leonardo, Arduino Micro, Arduino Yun or other ATmega32u4 based systems, you will
have to make a slight modification to IRLib.
IRLib uses your Arduino's built in hardware timers to generate an interrupt every 50µs so it can poll
the input pin to see if it has changed. By default it uses TIMER2. The Arduino servo library also uses
hardware interrupts using TIMER1. However the ATmega32u4 processor does not have TIMER2 so
IRLib defaults to TIMER1 on systems using that processor. You will have to modify IRLibTimer.h to
change the default timer. In that file at approximately line 70 you will see something like this:
#elif defined(__AVR_ATmega32U4__)
#ifdef CORE_TEENSY
// it's Teensy 2.0
//#define IR_SEND_TIMER1 14
//#define IR_SEND_TIMER3 9
#define IR_SEND_TIMER4_HS 10
#else
/* it's probably Leonardo */
#define IR_SEND_TIMER1 9
//#define IR_SEND_TIMER3 5
//#define IR_SEND_TIMER4_HS 13
#endif
© Adafruit Industries https://learn.adafruit.com/using-an-infrared-library Page 17 of 23