ArduinoLibs
|
Manages the reception of RC-5 commands from an infrared remote control. More...
#include <IRreceiver.h>
Public Member Functions | |
IRreceiver (int interruptNumber=0) | |
Constructs a new infrared remote control receiver that is attached to interruptNumber. | |
int | command () |
Returns the next command from the remote control. More... | |
int | system () const |
Returns the system number of the previous command(), indicating whether the command was for a TV, VCR, CD player, etc. More... | |
int | systemFilter () const |
Returns the system to filter commands against, or -1 if no filter is set. More... | |
void | setSystemFilter (int system) |
Sets the system to filter commands against, or -1 to turn off the system filter. More... | |
Static Public Attributes | |
static const int | AUTO_REPEAT = 128 |
Flag that is added to the output of command() when the command is an auto-repeated button press rather than the original button press. | |
Friends | |
void | _IR_receive_interrupt (void) |
Manages the reception of RC-5 commands from an infrared remote control.
IRreceiver recognizes commands in the Philips RC-5 protocol. This is a fairly common infrared protocol, supported by most universal remote controls. Program the universal remote to simulate a Philips TV, VCR, CD player, etc.
This class uses interrupts to process incoming bits from a standard 3-pin infrared receiver:
Typically, pin 1 of the receiver should be connected to the Arduino interrupt pin (e.g. D2), pin 2 should be connected to GND, and pin 3 should be connected to 5V. Consult the datasheet for your receiver to be sure though; some receivers may have different pin assignments.
The receiver is initialized by constructing an instance of the IRreceiver class:
By default, interrupt 0 on pin D2 is used. To change to another interrupt, pass its number to the constructor:
Currently this class can only handle a single instance of IRreceiver being active in the application. It isn't possible to have separate IRreceiver instances on different pins. Usually this won't be a problem because the same receiver can process inputs from multiple remotes.
The application retrieves incoming infrared commands by calling the command() function. The return value indicates the type of command:
If the command is an auto-repeat of a previous button press, then the AUTO_REPEAT flag will be set in the value returned from command(). The application can choose to ignore all auto-repeats, process all auto-repeats, or choose which button to auto-repeat based on its code:
By default, command codes will be generated for every type of RC-5 remote control, be it a TV, VCR, CD player, or something else. The application can distinguish between the remote controls using system(); noting that command() must be called before system() for the system value to be valid. For example, the following code could be used in a two-player video game where the first player's remote is configured as a TV and the second player's remote is configured as a VCR:
If the application only cares about a single system and wishes to ignore all other systems, it can configure a system filter at startup:
The complete list of RC-5 system numbers and command codes is given in the RC5.h header file.
Definition at line 29 of file IRreceiver.h.
int IRreceiver::command | ( | ) |
Returns the next command from the remote control.
Returns -1 if there is no new command, or the number between 0 and 127 corresponding to the command. If the command is an auto-repeat button press rather than an original button press, then the AUTO_REPEAT flag will be set.
The companion function system() will return the system number for the command indicating whether the command is for a TV, VCR, CD player, etc. By default, all systems are reported; use setSystemFilter() to filter out commands from all but a specific system.
The next call to command() will return -1 or the code for the next button press.
The header file RC5.h
contains a list of command codes for common remote controls.
Definition at line 220 of file IRreceiver.cpp.
|
inline |
Sets the system to filter commands against, or -1 to turn off the system filter.
If system is -1, then all received systems are returned via command() and system() irrespective of whether they are for a TV, VCR, CD player, or some other type of system. If system is set to anything other than -1, then only commands for that system are returned via command(). For example:
Definition at line 40 of file IRreceiver.h.
|
inline |
Returns the system number of the previous command(), indicating whether the command was for a TV, VCR, CD player, etc.
The return value from this function is valid only after a call to command(). The next call to command() will clear the system value, possibly to -1 if there is no new command.
The header file RC5.h
contains a list of system numbers for common remote controls.
Definition at line 37 of file IRreceiver.h.
|
inline |
Returns the system to filter commands against, or -1 if no filter is set.
If this value is -1, then all received systems are returned via command() and system() irrespective of whether they are for a TV, VCR, CD player, or some other type of system. If this value is set to anything other than -1, then only commands for that system are returned via command().
Definition at line 39 of file IRreceiver.h.