I have just stumbled across the IRremote library by Ken Sheriff.
I have it working on an Arduino UNO and it's all working great.
I would like to know how to capture multiple IR keypresses until a # (or any specific character) is encountered in the input but there doesn't seem to be an example for this.
I'm trying to create an infrared keypad I guess.
So it would be like entering a number into a phone and then pressing the dial button.
Something like 1234#
Once the # is encountered it will send the 1234 (which is the number entered) via serial to the terminal.
Could some kind soul please help by providing a simple example to do this ?
An IR Remote does not send ASCII characters that match the characters printed on the key. They will send a key code for the key you press. Part of your job will be mapping key codes to ASCII characters.
Once you have mapped an incoming key code to an ASCII character you save the character as you would any other keyboard input. Look at any of the many keypad-lock examples.
I think that the easiest way would be to have a pattern like *1234#, this would simplify a bit you're code. You would have a starting char for the seqience , so in the code you will have to test for the * pressed with the corresponding IR code from the remote. Then after this you would store in a array the keys pressed until you press the #
@John
and @tvcsantos
Thanks for the replies , agreed.
I don't think we need a full library here. @John if that's from the keypad library , it expects a keypad on certain pins not so ?
Anyways I have put together some code but am just battling with the array , if someone could point out/check where I am going wrong I would appreciate it.It's probably a simple bit of coding but oh man I am battling. And more than likely there a many ways to do this too.
The code doesn't work/compile yet as I have added the array in and keep getting complaints about the wrong data type so I can't compile it to check if it's functional.
Here's the code so far:
//LIBARARY CREDITS TO :
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int IRpin = 11; // pin for the IR sensor
int LED = 13; // LED pin
char ButtonVal[4]; // <<not sure what datatype is needed here :-(
IRrecv irrecv(IRpin);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(LED, OUTPUT);
}
void loop()
{
digitalWrite(LED, LOW);
if (irrecv.decode(&results))
{
IRkeymap();
ButtonVal[4] = IRkeymap();
if (ButtonVal[] == '#') //<<also here.. and I think this is where the decision should be perform an action like lock
{
Serial.println("You pressed # ");
}
Else{
irrecv.resume(); // Receive the next value
}
}
}
void IRkeymap(){ //map IR result to remote key
switch(results.value)
{
case 17769310:
Serial.println("1");
ButtonVal.0 = {"1"};
break;
case 17736670:
Serial.println("2");
ButtonVal.1 = {"2"};
break;
case 17752990:
Serial.println("3");
ButtonVal.2 = {"3"};
break;
case 17765230:
Serial.println("4");
ButtonVal.3 = {"4"};
break;
case 17738710:
Serial.println("#");
ButtonVal.3 = {"#"};
break;
case 0xFFFFFFFF:
Serial.println(" REPEAT")
;break;
default:
digitalWrite(LED, HIGH);
}// end case
delay(500); // Ignore immediate repeat
}
Thank you kindly for the comments so far. And as always any code/tips/tricks and comments are much appreciated.