This is an apparent bug with the Mega 2560. So far it has been found to not occur with a Duemilanove, but three different Mega 2560s have gotten it to occur.
When the code contains three or more exclamations it will prevent the sketch from being able to complete uploading. Note that there is no compile errors. However eventually there may be a timeout from avrdude.
An example set of code that causes this behavior is:
int IncrementingInteger = 1345;
int AlarmTriggerInteger = 1355;
boolean BooleanAlarmTriggered = false;
void setup() {
Serial.begin( 9600 );
}
void loop() {
delay( 5000 );
IncrementingInteger = IncrementingInteger + 1;
Serial.print( "Incrementing integer: " );
Serial.println( IncrementingInteger );
Serial.print( "Alarm trigger integer:" );
Serial.println( AlarmTriggerInteger );
if ( BooleanAlarmTriggered == false ) {
if ( IncrementingInteger == AlarmTriggerInteger ) {
BooleanAlarmTriggered = true;
Serial.println( "Alarm has gone off!!!" );
}
}
}
Removing just one of the exclamation marks from the Serial.println ( "Alarm has gone off!!!" ); will allow the sketch to upload normally and it will work as expected. I was unable to find reference to this problem otherwise.
Devices used:
Arduino Mega 2560 with Arduino IDE 0022 on a Windows 7 64bit. - Problem occurs.
Duemilanove with Unknown IDE Version on a Windows 7 64bit. - No problem.
Second Arduino Mega 2560 with Arduino IDE 0022 on OSX. - Problem occurs.
Third Arduino Mega 2560 with Arduino IDE 0021 on Ubuntu 10.04 64bit - Problem occurs.
This was originally raised in thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294452951/0#0If any further information is needed, please let me know.