Is the first code sent the relevant button code and then it's just FF's after that until button is released? If so then all you need do is remember the last button press that was not FF and if you then get FF just substitute it for the last button press. Something along the lines of
Yes, first code is sent then all repeat are F's.
Thanks so much Riva. I tried with your suggested sketch structure. I just change the byte to int since it's a 32 bit code.
Strange thing is when I press the Up button, the LED pin 7 just stays High, if I press Down button, the LED pin 8 also stays High, both will stay High until I press Up again or Down and hold. If I press and hold it, both buttons work correct ![]()
So press and hold works but now single press does not work.
My goal is press up or down, pin high for a time depending one delay or
press and hold, pin is high until released.
this is what I have:
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
int led7 = 7;
int led8 = 8;
void setup()
{
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
}
void loop() {
//static byte lastValue; // Place to store last value
int lastValue;
if (irrecv.decode(&results)) { // Check for IR button press
int newValue = results.value; // Get IR code
if (newValue == 4294967295) { // NEC repeat button pressed?
newValue = lastValue; // Substitute last not repeat code
}
else { // Not repeat code
lastValue = newValue; // Store last not repeat code
}
switch (newValue) {
case 2011287691:
//do something when var equals 1
digitalWrite(led7, HIGH);
delay(50);
break;
case 2011279499:
//do something when var equals 2
digitalWrite(led8, HIGH);
delay(50);
break;
default:
// if nothing else matches, do the default
// default is optional
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
break;
}
irrecv.resume(); // Receive the next value
}
}