Hi,
I just bought a remote control kit and it works just fine. But when I keep the key pressed for too long it returns a very high value. Is there any way to "ignore" long presses?
This is the code I'm using (copied from a tutorial):
#include <IRremote.h>
int RECV_PIN = 11; //define input pin on Arduino
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
void loop() {
if (irrecv.decode(&results)) {
if(results.value < very_long)
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
Should do it.
I just need to define the very_long variable to a value right?
I also noticed that when the remote control is turned to the opposite direction of the receiver the values are different, and also values get different as I move (the near/far away) the remote control to the receiver. Is this normal?
So if I create a switch case, should I include the multiple values I got for the same button or just ignore them?
should I include the multiple values I got for the same button or just ignore them?
You are better off using if statements and using a range of numbers. If you have a nominal number you can compare to if it is close to what you want. Something like this:-
upperLimit = nominalNumber + range;
lowerLimit = nominalNumber - range;
if( actualNumber > lowerLimit && actualNumber < upperLimit) { // you have a hit so do stuff
I got the idea, thanks for all the tips.