Skip to content
Rafi Khan edited this page Aug 16, 2015 · 9 revisions

Arduino IRremote API Reference

Note this is a work in progress

This documents the API for adding

IRSend

  • sendRaw:

Usage: This function is very useful when using Analysir to get the raw IR data , or when you have the raw data available. It can also be useful when working through adding a new protocol to the library.

(unsigned int buf[], unsigned char len. unsigned char hz)

Arguments:

buf[] : An array of unsigned integers which contains the raw ir data.

len : An unsigned char which has value of the length of the buffer, see the examples to determine this value.

hz : An unsigned char which has the value of the IR carrier frequency in khz.

			 TODO: Rename this to khz as the value stored is Khz not hz.

Description: This function is used to send RAW IR data. It works by calling enableIROut(hz) where the carrier frequency is given in Khz, then it loops through buf[]. Every odd space in the array is a space and the rest are marks. After it has finished sending the IR data it ends on a space(0), that is it ends with the LED off.

Example:

The following example shows how you can send a Mitsubishi AC signal using sendRaw, the data was collected using Analysir. In the example, the calls to sizeof() are used to determine the len argument of the call to sendRaw.

NOTE: This example only works if using the latest code from the master! A new release will soon be available and this note will be removed.

#include "IRremote.h"

int khz=38; // carrier frequency

unsigned int Signal_0_0[] = {8341,3541,576,1600,576,491,555,1600,576,1600,555,491,555,491,555,1600,555,1600,555,491,555,491,555,1621,555,1600,555,491,555,1600,555,491,555,1600,576,1600,555,1600,555,491,555,1600,555,491,555,491,555,491,555,1600,555,491,555,1600,555,1600,555,491,555,512,555,491,555,1579,576,448,555,16383,8341,3541,555,491,555,1600,576,491,555,491,555,1600,555,1600,555,491,555,512,555,1600,576,1600,555,491,555,491,555,1600,576,491,555,1600,555,491,555,491,555,491,555,1600,555,491,555,1600,555,1600,555,1600,555,491,555,1579,512,555,555,491,555,1600,555,1600,555,1600,576,491,555,1557,576,16383,8341,3541,555,1600,576,491,555,1600,555,1600,576,491,555,491,555,1600,555,1600,555,512,555,491,555,1600,576,1600,555,512,555,1600,555,491,555,1600,576,1600,555,1600,555,491,555,1621,576,491,555,512,555,491,555,1600,555,491,533,1621,555,1600,555,491,555,491,576,491,576,1600,555,448,555}; // the raw ir data


void setup()
{
}

void loop
{
   irsend.sendRaw(Signal_0_0, sizeof(Signal_0_0)/sizeof(int), khz); 
   delay(2000);
}
  • mark:

Usage: To send an IR mark for the specified number of microseconds

(int time)

Arguments:

time : specifies the number of microseconds for the mark

Description:

This works by enabling PWM output on the IR send pin and then calling custom_delay_usec() with the time specified.

  • space:

Usage: To leave the PWM output of the send pin off for the specified number of microseconds. A space is no output.

(int time)

Arguments:

time : specifies the number of microseconds for the space

Description:

This works by disabling PWM output on the IR send pin and then calling custom_delay_usec() with the time specified.

  • enableIROut:

Usage: To enable IR output. the khz value controls the modulation frequency in kilohertz.

(int khz)

Arguments:

khz : controls modulation frequency in kilohertz

Description: Disables the Timer interrupt and then sets up PWM output on the send pin. Lastly, it sets up the carrier frequency using khz.

  • custom_delay_usec:

Usage: Allows us to workaround Arduino's delayMicroseconds limit.

(unsigned long uSecs)

Arguments:

uSecs: : Specifies the duration of the delay.

Description:

A custom delay function that works by calling on micros() and checking for overflow.

IRReceive

  • decode

Usage:

Decodes the received IR message. Returns 1 if data is ready, otherwise returning 0

(decode_results *results)

Arguments:

results: a pointer to the decoded results

Description:

Decodes the received IR message and stores it in results

Clone this wiki locally