IR.resume() blocking or non-blocking

I am wondering if IR.resume() is blocking or non-blocking.
And does .resume() return any value when finished?
Specifically, I want to get rid of the delay() that most / all examples show.
How fast can a human press a button on a remote and then for the remote to send the signal out and then for the sensor to receive it and process it and then the Arduino to process it, that must take ages by itself?
So can we just remove any delay() or should we replace it with millis().
I don't know.
When testing in TinkerCad it certainly works without any delay().

#include <IRremote.h>
const int IRpin = A4; // IR receiver to Arduino Pin

IRrecv myIRreceiver(IRpin); // Receive on IRpin
decode_results results;

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

void loop() {
  if (myIRreceiver.decode(&results)) 
  {
    Serial.println(results.value, HEX);

    switch (results.value)
    {
      case 0xFD00FF:    Serial.println("POWER");
        break;
      case 0xFD30CF:    Serial.println("0");
        break;
      default:
        Serial.println("unknown button");
    } // end switch

    //delay(500); // Avoid repeat signal from remote control e.g. do not get quickly repeated button press
    myIRreceiver.resume(); // After receiving, this must be called to reset the receiver tiny memory space and prepare it to receive another code.

  } // end if
  
} // end of main loop

resume() is non blocking, it just tells the state machine to forget the previous signals and start listening again from scratch.

/**
 * Restart the ISR state machine
 * Enable receiving of the next value
 */
void IRrecv::resume() {
    irparams.rcvstate = IR_REC_STATE_IDLE;
}

Note that if you downloaded the IRremote library recently, it's undergoing significant changes. Doing

  if (myIRreceiver.decode(&results))

is now obsolete.

You should read the documentation and look at the new examples.

To your question, it depends what is sending the signal. most remote controls would auto-repeat but include a pause in between two transmissions (and possibly send a repeat code rather than the same code again) - so there is no "bouncing" as you could see with a regular push button

The delay is thus useless, what your program needs to do is handle properly a duplicated command - and as said previously, depending on your remote, the repetition can be a different code (in which case your program will just ignore it because it won't be recognized). if it's the same code being sent, then your program needs to remember the last command and when it arrived (use millis()) and then when you get a new command, compare to the previous one and ignore it if it is the same happening too soon -> using millis() to compare with the previous stored value will help do that.

// assume we stored in oldCode the previous command and in previousMillis the moment it was received 

uint32_t newCode = results.value;
if ((newCode == oldCode) && (millis() - previousMillis < 5000)) {
 // same code sent within 5 seconds... decide what to do with it
  ...
} else {
  // OK to handle
  ...
  oldCode = newCode;
  previousMillis = millis();
}

Thank you for the excellent explanation. Best I have read so far.
Now, regarding TinkerCad, they have the old(er) version of the library.
Could you just send the new version to Autodesk, Inc. or whoever owns TinkerCad.
Is the new version not backwards-compatible?
I am just curious because I'm a teacher and my high-school students are stuck with whatever is available during online-learning at home. Meaning, we are still studying the old code examples.
Our virtual classroom project will work fine the way you have explained it.

Could you just send the new version to Autodesk, Inc. or whoever owns TinkerCad.

I'm just a member of this forum, like you...You can open a ticket (submit.a request) to the TinkerCad team.

Is the new version not backwards-compatible?

The current "under development" version is 3.0 and the one you are using probably 2.2.0
I'm unsure if they plan to maintain backward compatibility as they are changing the way you structure the code.

Best would probably be to send your request to the maintainer of the library, Armin Joachimsmeyer. He is listing his eMail on the GitHub repository

I am just curious because I'm a teacher and my high-school students are stuck with whatever is available during online-learning at home. Meaning, we are still studying the old code examples.

Kuddos to you to invest time and efforts to keep the students busy and learning. You are doing something really important in general, and all the more in these days and times. So million thanks for your work.

Studying the old examples is OK as long as the test environment is built around the old library. As long as your students understand the concepts, they should be fine indeed.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.