RF24 watch RF pipe while rest of sketch runs

Am wanting to add 2 way comms between 2 Mega boards.

I have the NRF24L01 modules, and am about to complete the wiring on a breadboard.

My sketch requires that the RF pipe is monitored while the rest of the sketch continues to loop.

Had a look at the PingPair example that came with the rf24 library and have coded as follows ( not yet tested ) :

rfDataArrived = 0;
		if ( radio.available() ){
			bool done = false;
			while (!done){
			  done = radio.read( &duino2, sizeof(duino2) );
				// do something with the variables and commands received in the duino2 struct
				if(duino2.mType == 1) rfDataArrived = 1;
			}
			radio.stopListening();
			if(duino2.mType == 1){ // this is new incoming data - not a ping back
				delay(50);  // short delay so sender can change back to listening
				duino2.mType = 2; // change the mType flag to a ping reply data type - so other receiver does not process it.
				radio.write( &duino2, sizeof(duino2) );  // ping back the data received
				radio.startListening();
			}
		}

, but I don't seem to find an answer to the following :

  1. would a sketch stop executing ( looping ) if it is listening for a radio signal, or would it only pause for a short while when radio data starts to arrive ?

or should this be changed to detect the INT pin on the radio connected to the Arduino interrupt pin/s ?

Regards

This code is designed for use in a non-blocking sketch. The sketch would execute this code at regular intervals and handle radio messages as they arrive. You would need to design the rest of your sketch to be non-blocking too, so that it can execute this code periodically.

PeterH:
This code is designed for use in a non-blocking sketch. The sketch would execute this code at regular intervals and handle radio messages as they arrive. You would need to design the rest of your sketch to be non-blocking too, so that it can execute this code periodically.

Thanks for the prompt reply PeterH

So are you saying that the normal loop would bypass the rf code, until the loop detects incoming data ? And at that point, it would execute the rf section of code and when that is completed, would then continue with the rest of the sketch ?

DaveO:
So are you saying that the normal loop would bypass the rf code, until the loop detects incoming data ? And at that point, it would execute the rf section of code and when that is completed, would then continue with the rest of the sketch ?

Yes, if I understood you correctly. It will evaluate radio.available() repeatedly, and it will only execute the body of the 'if' statement when radio.available() indicates that there is a message available.