Sorry. Of course >= is evaluated before &&. I just
get confused when retrolefty suggested parenthesis and
I just thought the original code was ok without (as it was)
and did not notice the false suggest.
So
!dOn && ( n1000 >= 500000L ) == !dOn && n1000 >= 500000L
as it was in the original code.
Here is the code as whole with all the mods requested:
const int dummyPort = 7;
void setup() {
Serial.begin(115200);
Serial.println("Start Arduino");
pinMode(dummyPort, OUTPUT);
}
unsigned long n1000 = 0;
boolean dOn = false;
void loop() {
//n1000 = micros();
//while ( n1000 > 1000000L) n1000 -= 1000000L; // This works
n1000 = micros() % 1000000L; // This hangs Arduino while pressing reset
if ( !dOn && ( n1000 >= 500000L ) ) {
digitalWrite(dummyPort, 1);
dOn = true;
}
if ( dOn && ( n1000 < 500000L ) ) {
digitalWrite(dummyPort, 0);
dOn = false;
}
}
And the real problem still exist on that code: Reseting while in modulo hangs the Arduino