Commit 9513494e authored by Chris Young's avatar Chris Young

upgrade from 1.0 to 1.1

New version 1.1 adds 2 new examples. Minor changes to core code to deal
with sketches that are "receive only" which are connected to hardware
that has an output circuit. See CHANGELOG.txt for details.
parent 54f9953b
Change Log for IRLib – an Arduino library for infrared encoding and decoding
Copyright 2013 by Chris Young
April 2013 Version 1.1 Constructor of IRsendBase now initializes output
pin and forces it low immediately.
New IRrecv::No_Output() method initializes output
pin and forces it low. Use this in sketches which
receive only by the have output hardware connected.
Added examples IRservo and IRserial_remote
February 2013 Version 1.0a Removed debugging test switch which was accidentally
left on in file "IRLib.h"
January 2013 Version 1.0 Initial Release
\ No newline at end of file
/* IRLib.cpp from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.0 January 2013
* Version 1.1 April 2013
* Copyright 2013 by Chris Young
* This library is a major rewrite of IRemote by Ken Shirriff which was covered by
......@@ -696,6 +696,15 @@ IRrecv::IRrecv(int recvpin)
irparams.recvpin = recvpin;
irparams.blinkflag = 0;
/* If your hardware is set up to do both output and input but your particular sketch
* doesn't do any output, this method will ensure that your output pin is low
* and doesn't turn on your IR LED or any output circuit.
void IRrecv::No_Output (void) {
digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low
void IRrecv::enableIRIn() {
// setup pulse clock timer interrupt
......@@ -804,6 +813,10 @@ ISR(TIMER_INTR_NAME)
IRsendBase::IRsendBase () {
digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low
void IRsendBase::enableIROut(int khz) {
// Enables IR output. The khz value controls the modulation frequency in kilohertz.
/* IRLib.h from IRLib an Arduino library for infrared encoding and decoding
* Version 1.0 January 2013
* Version 1.1 April 2013
* Copyright 2013 by Chris Young
* This library is a major rewrite of IRemote by Ken Shirriff which was covered by
......@@ -151,7 +151,7 @@ public:
class IRsendBase
IRsendBase() {};
IRsendBase() ;
void sendGeneric(unsigned long data, int Num_Bits, int Head_Mark, int Head_Space, int Mark_One, int Mark_Zero, int Space_One, int Space_Zero, int mHz, bool Stop_Bits);
void enableIROut(int khz);
......@@ -227,6 +227,7 @@ class IRrecv
IRrecv(int recvpin);
void No_Output(void);
void blink13(int blinkflag);
bool GetResults(IRdecodeBase *decoder);
void enableIRIn();
IRLib – an Arduino library for infrared encoding and decoding
Version 1.0 January 2013
Version 1.1 april 2013
Copyright 2013 by Chris Young
This library is a major rewrite of IRemote by Ken Shirriff which was covered
......@@ -59,6 +59,9 @@ IRsendDemo Simplistic demo to send a Sony DVD power signal every time a
IRsendJVC Demonstrates sending a code using JVC protocol which is tricky.
Samsung36 Demonstrates how to expand the library without recompiling it.
Also demonstrates how to handle codes that are longer than 32 bits.
IRservo Demonstrates controlling a servo motor using an IR remote
IRserial_remote Demonstrates a Python application that runs on your PC and sends
serial data to Arduino which in turn sends IR remote signals.
Note: I did not port any of the other demo sketches although I may add IRTest later.
The library handles the following protocols:
#include <IRLib.h>
IRsend My_Sender;
int protocol;
long code;
int bits;
void setup() {
long parseHex (void) {
long Value=0; char C;delay(100);
while (Serial.available()>0) {
C= tolower(;
if ((C>='0')&&(C<='9'))
if ((C>='a') && (C<='f'))
return Value;
Value= C+(Value<<4);
return Value;
void parseDelimiter () {
char C;
while(Serial.available()>0) {
if( (C>='0') && (C<='9') )return;
if( (C>='a') && (C<='f') )return;;//throwaway delimiters
delay (5);
void loop() {
if (Serial.available ()>0) {
protocol = Serial.parseInt (); parseDelimiter();
code = parseHex (); parseDelimiter();
bits = Serial.parseInt (); parseDelimiter();
/* Serial.print("Prot:"); Serial.print(protocol);
Serial.print(" Code:"); Serial.print(code,HEX);
Serial.print(" Bits:"); Serial.println(bits);
My_Sender.send(IRTYPES(protocol), code, bits);
# IRLib demo script
# version 1.0 by Chris Young
# Displays a "Virtual remote" on your screen. Clicking on the
# buttons sends serial datato the Arduino which in turn
# since IR signals to a cable box in TV.
# Import all of the necessary pieces of code
import serial, sys, pygame, pygame.mixer
from pygame.locals import *
# You will have to edit this to the proper port and speed
ser = serial.Serial('COM4', 9600)
# Established screen size, size of buttons and position
size = width, height = 400, 768
button_size=54; button_offset=71
max_rows=10; max_columns=4
# Specify a font. I'm using Arial narrow bold from my Windows
# font folder. However the default font shown below also works.
myfont =pygame.font.Font ("c:/windows/fonts/ARIALNB.TTF",30)
# These are the text labels that will appear on each button
label_text=("TVp", "CBp", "P^", "Pv",\
"<<", ">", ">>", "->",\
"Rec", "=", "s", "<-",\
"Gd", "^", "Fav", "Inf",\
"<", "sel", ">", "Lis",\
"ret", "v", "Prv", "Mnu",\
"1", "2", "3", "Ch+",\
"4", "5", "6", "Ch-",\
"7", "8", "9", "Vol+",\
"Pip", "0", "Mut", "Vol-",\
# Each of these 40 strings of text correspond to the
# protocol in code which will be sent over the USB serial
# to the Arduino. The first number is the protocol number.
# See the defined protocols in "IRLib.h"for the
# enum IRTYPES at about line 50. This example uses
# protocol 3 which is "RC5" used by my Magnavox TV
# and protocol 5 "PANASONIC_OLD" used by my Scientific
# Atlantic SA 8300 DVR. The protocol number is followed by
# the hex code to be transmitted. That is followed by the
# number of bits. Note that the PANASONIC_OLD protocol
# does not need the number of bits specified so they are omitted.
IR_Codes= ("3,180c,13","5,37c107","5,36d924","5,37d904",\
# This function gets called to shut everything down
def Finished():
# Gets the button index based on mouse position. Returned
# value is from 0 to 39 (number of buttons-1)
# Returns -1 if you are not over a button.
def ComputeButton():
bx=mx/button_offset; by=my/button_offset
if bx<0 or bx>=max_columns:return -1
if by<0 or by> max_rows:return -1
if (mx%button_offset)>button_size:return -1
if (my%button_offset)>button_size:return -1
return bx+by*max_columns
# Blits the button text from button number "i"
# onto the specified layer using the specified color.
def Show_Text(i,Layer,color=(0,0,0)):
label = myfont.render (t,1,color)
labelpos= label.get_rect()
# Create the screen and load the background image.
screen = pygame.display.set_mode(size)
bg = pygame.image.load("remotebg.png")
# Blit black text labels onto the background image
for i in range (max_rows*max_columns):
Show_Text(i, bg)
# Copy the background to the display
# Load the clicking sound
# Used to detect when the mouse hovers over a different button
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
elif event.type == KEYDOWN and event.key == K_ESCAPE:
Finished ()
elif event.type == MOUSEBUTTONDOWN:
i=ComputeButton() #which button did we click
if i>=0: #play the sound
ser.write(IR_Codes[i]) #send the codes
elif event.type==MOUSEMOTION:
i=ComputeButton() #which button are we over
if i!=previous: #difference in the last one?
if i>=0: #turn it red
else: #or put it back the way it was
pygame.display.flip() #update the display
# That's all folks
//POV-Ray source to generate the background image for IRserial_remote
// create rectangular areas with rounded corners for use as
// buttons and background objects.
// Render at 1024x768 then crop 312 pixels from each side
// leaving 400x768 final image.
#declare Area=15; //size of area lights
#declare CR=0.1; //corner radius
#declare ER= 0.5; //edge radius
#declare CX= 3; //width from corner to corner
#declare CY= 7.75; //height from corner to corner
#declare BZ=-ER; //Z offset for buttons
plane {z,0 pigment{rgb<0.8,0.85,1>*0.8}}//background
#macro Thing (ER,CR,CX,CY,T)
#local Corner=
union {
torus {CR,ER rotate x*90}
cylinder {ER*z,-ER*z,CR}
union {
object{Corner translate< CX,CY,0>}
object{Corner translate<-CX,CY,0>}
object{Corner translate< CX,-CY,0>}
object{Corner translate<-CX,-CY,0>}
cylinder{CY*y,-CY*y,ER translate<-CX-CR,0,0>}
cylinder{CY*y,-CY*y,ER translate< CX+CR,0,0>}
cylinder{CX*x,-CX*x,ER translate<0,-CY-CR,0>}
cylinder{CX*x,-CX*x,ER translate<0, CY+CR,0>}
texture {T}
#declare BX= 0.4; #declare BY=BX;//size of the buttons
#declare White_Texture=texture{pigment{rgb 1}finish {ambient 0.3}}
#declare Blue_Texture=texture{pigment {rgb<0.85,0.9 ,1>}}
object {Thing(ER,CR,CX,CY, White_Texture)}//main object
//loop through the buttons
#declare R=-4.5;
#while (R<5.5)
#declare C=-1.5;
#while (C<=1.5)
object{Thing(0.1,0.2,(BX*0.8),(BY*0.8), Blue_Texture)
translate <C*BX*4,R*BY*4,BZ>
#declare C=C+1;
#declare R=R+1;
light_source{<50,50,-100>*5 color 0.8
#if (Area)area_light x*Area,y*Area,9,9#end
light_source{<0,0,-400>*3 rgb 1}
camera{orthographic location <0,0,-120> look_at <0,0,0> angle 11 }
//That's all folks!
\ No newline at end of file
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.1 April 2013 by Chris Young
* "IRservo" Control a servo using an IR remote
#include <IRLib.h>
#include <Servo.h>
// You will have to set these values depending on the protocol
// and remote codes that you are using. These are from my Sony DVD/VCR
#define RIGHT_ARROW 0x86bca //Move several clockwise
#define LEFT_ARROW 0x46bca //Move servo counterclockwise
#define SELECT_BUTTON 0xd0bca //Center the servo
#define UP_ARROW 0x42bca //Increased number of degrees servo moves
#define DOWN_ARROW 0xc2bca //Decrease number of degrees servo moves
#define BUTTON_0 0x90bca //Pushing buttons 0-9 moves to fix positions
#define BUTTON_1 0x00bca // each 20 degrees greater
#define BUTTON_2 0x80bca
#define BUTTON_3 0x40bca
#define BUTTON_4 0xc0bca
#define BUTTON_5 0x20bca
#define BUTTON_6 0xa0bca
#define BUTTON_7 0x60bca
#define BUTTON_8 0xe0bca
#define BUTTON_9 0x10bca
IRrecv My_Receiver(11);//Receive on pin 11
IRdecode My_Decoder;
Servo My_Servo; // create servo object to control a servo
int pos; // variable to store the servo position
int Speed; // Number of degrees to move each time a left/right button is pressed
void setup()
My_Receiver.No_Output();//Turn off any unused IR LED output circuit
My_Servo.attach(9); // attaches the servo on pin 9 to the servo object
pos = 90; // start at midpoint 90 degrees
Speed = 3; // servo moves 3 degrees each time left/right is pushed
My_Servo.write(pos); // Set initial position
My_Receiver.enableIRIn(); // Start the receiver
void loop()
if (My_Receiver.GetResults(&My_Decoder)) {
if(My_Decoder.decode_type==MY_PROTOCOL) {
switch(My_Decoder.value) {
case LEFT_ARROW: pos=min(180,pos+Speed); break;
case RIGHT_ARROW: pos=max(0,pos-Speed); break;
case SELECT_BUTTON: pos=90; break;
case UP_ARROW: Speed=min(10, Speed+1); break;
case DOWN_ARROW: Speed=max(1, Speed-1); break;
case BUTTON_0: pos=0*20; break;
case BUTTON_1: pos=1*20; break;
case BUTTON_2: pos=2*20; break;
case BUTTON_3: pos=3*20; break;
case BUTTON_4: pos=4*20; break;
case BUTTON_5: pos=5*20; break;
case BUTTON_6: pos=6*20; break;
case BUTTON_7: pos=7*20; break;
case BUTTON_8: pos=8*20; break;
case BUTTON_9: pos=9*20; break;
My_Servo.write(pos); // tell servo to go to position in variable 'pos'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment