ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Attributes | Friends | List of all members
IRreceiver Class Reference

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)
 

Detailed Description

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:

irchip.jpg

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:

IRreceiver ir(1); // Interrupt 1 on pin D3

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:

void loop() {
switch (ir.command()) {
case RC5_0: case RC5_1: case RC5_2: case RC5_3: case RC5_4:
case RC5_5: case RC5_6: case RC5_7: case RC5_8: case RC5_9:
// Process a digit
...
break;
case RC5_ERASE:
// Backspace/erase last digit.
...
break;
case RC5_STANDBY:
// Power on/off button.
...
break;
}
}

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:

void loop() {
switch (ir.command()) {
case RC5_INC_VOLUME:
case IRreceiver::AUTO_REPEAT | RC5_INC_VOLUME:
// Volume increase button pressed or held.
...
break;
case RC5_DEC_VOLUME:
case IRreceiver::AUTO_REPEAT | RC5_DEC_VOLUME:
// Volume decrease button pressed or held.
...
break;
case RC5_MUTE:
// Mute button (ignore auto-repeat).
...
break;
}
}

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:

void loop() {
int cmd = ir.command();
int sys = ir.system();
if (sys == RC5_SYS_TV)
player1(cmd);
else if (sys == RC5_SYS_VCR)
player2(cmd);
...
}

If the application only cares about a single system and wishes to ignore all other systems, it can configure a system filter at startup:

void setup() {
ir.setSystemFilter(RC5_SYS_VCR);
}

The complete list of RC-5 system numbers and command codes is given in the RC5.h header file.

See Also
DumpIR Example

Definition at line 29 of file IRreceiver.h.

Member Function Documentation

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.

See Also
system(), setSystemFilter()

Definition at line 220 of file IRreceiver.cpp.

void IRreceiver::setSystemFilter ( int  system)
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:

ir.setSystemFilter(RC5_SYS_VCR);
See Also
systemFilter(), system(), command()

Definition at line 40 of file IRreceiver.h.

int IRreceiver::system ( ) const
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.

See Also
command(), setSystemFilter()

Definition at line 37 of file IRreceiver.h.

int IRreceiver::systemFilter ( ) const
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().

See Also
setSystemFilter(), system(), command()

Definition at line 39 of file IRreceiver.h.


The documentation for this class was generated from the following files: