For what it is worth, I found an answer myself that is a little kludgy but works. After some experimentation, it became clear that the while() loop was interfering with event processing, including serial events. However, a for(…) loop does not. The following would not work in code that needed a rapid response to user input, but mine does not.
Assume for the purposes of this example that there is a boolean global variable, “ready”, that is controlled by actions outside the for() loop. In the specific instance here, if we receive a specific text string from the Arduino, we know that the action is complete and we are ready to move on to the next command. When the specific text string is received, ready is set to true.
We also know the longest that a response from the Arduino should or would take. In this case, maximum would be two minutes. There’s likely more elegant ways to do this, but here goes:
ready = false; //set to false before entering loop
sendFirstCommand();
for (int i = 0; i < 2401; i++) {
if (ready == true) //affected by process outside the loop, serial data coming to processing
break;
delay(50);
if ( i == 2400) {
println("Procedure on Arduino timed out");
}
}
if (ready == true)
sendSecondCommand();
else
myHandleErrorRoutine();
Note that there is an added benefit of having a timeout that can be set. I hope this is of value to someone.