2013/01/31

Freeduino/Arduino LCD IR Decoder

Output:

Code:

/*

 * LCDIRDecoder.pde: Freeduino/Arduino + cheaphousetek LCDKeypad Shield + IR Reveiver Breakout 
 * Ken Shirriff's IRremote.h page 
 * Original from Cooper Maa 
 * Modified on Jan. 31, 2013 by Befun Hung to fit pins of cheaphousetek LCD Keypad Shield
 */

#include <LiquidCrystal.h>               // include LiquidCrystal library
#include <IRremote.h>                    // include IRRemote library

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);     // modified to fit cheaphousetek LcdKeypad Shield

const int irReceiverPin = 2;             // IR Breakout Output Pin: Digital 2

IRrecv irrecv(irReceiverPin);            // define IRrecv object to receive IR singal
decode_results results;                  // decoded result is stored to variable rusult of struct decode_results

void setup() {
  lcd.begin(16, 2);                      // set numbers of rows and columns of LCD 
  lcd.print("IR Decoder");               // print "IR Decoder" message on LCD

  irrecv.blink13(true);                  // blinking pin 13 lcd on receiving IR singal
  irrecv.enableIRIn();                   // start IR decode    
}

// display IR protocol
void showIRProtocol(decode_results *results) 
{
  // judge IR protocol
  switch(results->decode_type) {
   case NEC:
     lcd.print("NEC");
     break;
   case SONY:
     lcd.print("SONY");
     break;
   case RC5:
     lcd.print("RC5");
     break;
   case RC6:
     lcd.print("RC6");
     break;
   default:
     lcd.print("Unknown");  
  }  

  // print IR code on LCD
  lcd.print(" ");
  lcd.print(results->value, HEX);        // IR code
  lcd.print(" (");
  lcd.print(results->bits);              // bytes of IR code    
  lcd.print(")");
}

void loop() {
  // set cursor to column 0, line 1
  // Note: line 1 is the second row,line 0 is the first row
  lcd.setCursor(0, 1);

  if (irrecv.decode(&results)) {         // successful decode, receiving a set of IR singal
    showIRProtocol(&results);            // display IR protocol
    irrecv.resume();                     // continue to receive the next IR singal        
  }    
}