I thought this might be of some interest to those who need a simple method to send keyboard data to their Arduino projects.
IR keypad used:
See the sketch below for implementation.
Attached is a modified Library to handle code IR reception.
Enjoy.
//
//44 button IR remote
//NEC - IR code
//LarryD
//
//This task demonstrates interfacing to a 44 button IR remote
//which is commonly available on EBay for $3 - $5 USD.
//These remotes usually come with a controller which includes a
//all in one IR detector and amplifier similar to TSOP38238.
//Remove the detector from the controller for this discussion.
//See: https://www.sparkfun.com/datasheets/Sensors/Infrared/tsop382.pdf
//Hook the sensor to Pin D2 for this sketch,
//for reference, see: https://learn.sparkfun.com/tutorials/ir-control-kit-hookup-guide
//Interrupt 0 (pin D2) is used to achieve fast receive response.
//
// Rev 1.0 January 1, 2015
//==========================================
//Original library was from
//https://github.com/adafruit/Adafruit-NEC-remote-control-library
//however, to remove blocking it was modified and assigned the name:
//Adafruit-NECremote44.h Adafruit-NECremote44.cpp
#include "Adafruit-NECremote44.h"
const byte irPin = 2;
Adafruit_NECremote remote(irPin);
volatile byte irFlag = 0;
const byte buttonCode[44] = {
0x5C,0x5D,0x41,0x40,
0x58,0x59,0x45,0x44,
0x54,0x55,0x49,0x48,
0x50,0x51,0x4D,0x4C,
0x1C,0x1D,0x1E,0x1F,
0x18,0x19,0x1A,0x1B,
0x14,0x15,0x16,0x17,
0x10,0x11,0x12,0x13,
0xC,0xD,0xE,0xF,
0x8,0x9,0xA,0xB,
0x4,0x5,0x6,0x7
}; //END of buttonCode Array
const byte ASCIIcode[44] = {
0x31,0x32,0x33,0x34,
0x35,0x36,0x37,0x38,
0x39,0x30,0x2A,0x23,
0x41,0x42,0x43,0x44,
0x45,0x46,0x47,0x48,
0x49,0x4A,0x4B,0x4C,
0x4D,0x4E,0x4F,0x50,
0x51,0x52,0x53,0x54,
0x55,0x56,0x57,0x58,
0x59,0x5A,0xFA,0xFB,
0xFC,0xFD,0xFE,0xFF
}; //END of ASCIIcode Array
//================================================
void setup(void)
{
Serial.begin(115200);
attachInterrupt (0, irISR, FALLING); // attach interrupt handler
} // END of setup()
//================================================
void loop(void)
{
//check if there is a code is coming in
if(irFlag)
{
//Button retrieval
int code = getCode();
if (code >= 0)
{
//button code to ASCII code conversion
for (int i = 0; i < 44; i++)
{
if (buttonCode[i] == code)
{
Serial.println(char(ASCIIcode[i]));
break;
}
}
}
} //END of Button retrieval
// Other loop stuff goes here
}// END of loop()
//================================================
int getCode()
{
detachInterrupt (0);
//get the code received from the remote
int c = remote.listen(-1); //a negative defaults to a code length of 80ms
irFlag = 0; //re-enable code capturing
attachInterrupt (0, irISR, FALLING);
return c;
} //END of getCode()
//================================================
// Interrupt Service Routine (ISR)
void irISR ()
{
irFlag = 1;
} // end of irISR()
Edit: ******* Changed interrupt to FALLING *******

Adafruit-NECremote44.zip (4.26 KB)

