Pardon me for coming late to the party.
Vesal: Are you by any chance using Linux? There are some known problems with the UNO Boot loader and /dev/ttyACM0 on Linux systems. (If you are not using Linux, then: Never Mind.)
Here's what I did:
I took your original program without the superfluous and confusing (to us mere humans) stuff:
I added a delay of 1 millisecond in the loop. Here's the code:
const int dummyPort = 13; // I use pin 13 since it already has an LED
void setup()
{
Serial.begin(115200);
Serial.println("Start Arduino");
pinMode(dummyPort, OUTPUT);
}
unsigned long n1000 = 0;
int dOn = 0;
void loop()
{
n1000 = micros() % 1000000;
if ( !dOn && n1000 >= 500000 ) {
digitalWrite(dummyPort, 1);
dOn = 1;
}
if ( dOn && n1000 < 500000 ) {
digitalWrite(dummyPort, 0);
dOn = 0;
}
delay(1);
}
When I do this, I see the three-blink bootloader sequence and then the LED blinks on and off with a period of about a second, which, I perceive, was your intent. I can reset by opening a terminal and I can reset by pressing button. All is Good on my Centos 5.5 system with Arduino version 0022 , avr-gcc version 4.3.4 built from source and with the latest version of the Optiboot boot loader from Google Code Archive - Long-term storage for Google Code Project Hosting.
However, if I delete the delay() statement, it repeatedly does the bootloader three-blink thing on the LED on pin 13 whenever I hit the button or when I open a terminal, and never gets to the code in the sketch.
If you are using Windows, then never mind (but I already said that). Maybe some of the other helpers can come up with something.
The code itself works just swell on Duemilanove boards as well as the UNO with my Linux system, although I might have written it a little differently. With the Duemilanove boards it doesn't need the delay() statement.
The problem is that something weird is with division.
I can state unequivocally (and I am unanimous in that) that it has nothing do do with division.
Regards,
Dave