Random IR receiver values when using millis(), but consistent otherwise?

Hi All,

I am having trouble transitioning a program off of using delay() to using millis(), but the only issue I'm facing now is the actually IR receiving code. For some reason the code comes back nice and consistent in one sketch but not the other. I've eliminated the hardware being the issue since it works perfectly in the first sketch, but acts wildly in the second.

Here is the portion of the sketch where the IR result value comes back consistently:

IRrecv irrecv(IR_PIN); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'

void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

pinMode(LED_PIN, OUTPUT);
pinMode(IR_PIN, INPUT);
}

void loop() {
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value
}
}

void translateIR() // takes action based on IR code receive
{
Serial.println(results.value, HEX);
}

Here is the sketch where the result comes back inconsistently and seemingly randomly:

unsigned long irInterval=500;
unsigned long irPreviousMillis=0;
IRrecv irrecv(IR_PIN); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'

unsigned long currentMillis = 0;

void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

pinMode(LED_PIN, OUTPUT);
pinMode(IR_PIN, INPUT);
}

void loop () {
currentMillis = millis();
readIR();
}

void readIR() {
if (irrecv.decode(&results)) // have we received an IR signal?
{
if (currentMillis - irPreviousMillis >= irInterval)
{
decodeIR();
irPreviousMillis = currentMillis;
}
irrecv.resume(); // receive the next value
}
}

void decodeIR()
{
Serial.println(results.value, HEX);
}

It seems strange that the second produces such different and inconsistent results. I found another forum post where someone seemed to be experiencing a similar issue but then unfortunately they threw a bit of a tantrum and didn't post the solution.

Please let me know if you have any questions, any help is appreciated!

Full sketches provided, the second is still underway, but I discovered this issue when checking the progress.

sketch1.ino (10.5 KB)

sketch2.ino (11.7 KB)

In theory, if you set irInterval to 0, the two should function the same. Have you tried that?