I am trying to make an operating hours counter with arduino, i started with a basic script to make the arduino work as a stop watch, This is my script:
unsigned long start=0, finish=0, elapsed=0;
void setup() {
Serial.begin(9600);
Serial.println("Clock START");
}
void displayResult(unsigned long elapsed){
float h,m,s,ms;
unsigned long over;
h=int(elapsed/3600000);
over=elapsed%3600000;
m=int(over/60000);
over=over%60000;
s=int(over/1000);
ms=over%1000;
Serial.print("Elapsed time: ");
Serial.print(h,0);
Serial.print("h ");
Serial.print(m,0);
Serial.print("m ");
Serial.print(s,0);
Serial.print("s ");
Serial.print(ms,0);
Serial.println("ms");
Serial.println();
}
void loop() {
start = millis();
delay(200);
Serial.println("Start");
Serial.println("doing Operations and stuff");
delay(800);
finish=millis();
elapsed=finish-start;
Serial.println("Ended !!!");
displayResult(elapsed);
}
Unfortuantly the arduino compiler blocks at the Uploading part, i tried compiling it at first without uploading, it gave me no warning errors. I tried compiling other scripts they worked, it only blocks for this stop watch code.
Thank you for your help