Omitting print statements stops program working

My robot can be controlled by Radio Control as well as being able to roam by itself. In the following piece of program I grab copies of some values which are updated in interrupt routines. I then print out those values ( statements in red) and the program then goes on and works fine.

If I comment out the print statements it does not work. It seems not to know the correct value of RC_ThrottleIn which is the first value printed. The delay caused by the print statements seems to be necessary for the value to be updated. If I put a delay of 100ms in instead of the print statements I get the same correct working.

What is happening?

bool getRC() {

// check shared update flags to see if any channels have a new signal noInterrupts(); // turn interrupts off quickly while we take local copies of the shared variables if(RC_UpdateFlagsShared) { RC_UpdateFlags = RC_UpdateFlagsShared; if(RC_UpdateFlags & RC_Throttle_FLAG) { RC_ThrottleIn = RC_ThrottleInShared; } if(RC_UpdateFlags & RC_Steering_FLAG) { RC_SteeringIn = RC_SteeringInShared; } if(RC_UpdateFlags & RC_OnOff_FLAG) { RC_OnOffIn = RC_OnOffInShared; }

RC_UpdateFlagsShared = 0;

}

interrupts(); // we have local copies of the inputs, so now we can turn interrupts back on

Serial.print("RC_ThrottleIn ");Serial.print(RC_ThrottleIn); Serial.print(" RC_SteeringIn ");Serial.print(RC_SteeringIn); Serial.print(" RC_OnOff ");Serial.println(RC_OnOff); ......... program continues

Post the complete sketch, your problem is probably in the variable declaration but that's just a wild guess.

The sketch is huge and does not fit in what is allowed (9500 chars) I have put the part that deals with the RC here

https://dl.dropboxusercontent.com/u/39488957/RC.ino

Just attach it, if it too big to post

The sketch is huge and does not fit in what is allowed (9500 chars) I have put the part that deals with the RC here

Attach the complete sketch, this one doesn't have setup and loop routines, so the flow is not clear.

If possible shorten the sketch to a minimal version that shows the same behavior but in your case this seems to be pretty complicated.