0


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

4
  • What's the error message? – Edgar Bonet May 2 '16 at 8:26
  • I don't get any message error, it just hangs there for 5 minuts at it just gave me : avrdude: stk500v2_ReceiveMessage(): timeout – Mehdi May 2 '16 at 8:30
  • Weird. I have no problem uploading and running this on my Mega. Looks like a communication problem. What is your OS? BTW: there is no point in using float variables here. – Edgar Bonet May 2 '16 at 8:36
  • I use windows 7, i also tried other usb ports but it just hangs for this exact script. – Mehdi May 2 '16 at 8:40
2

There is a bug in early versions of the Mega2560 bootloader. It crashes on !!! (or enters some other special state that stops uploading happening).

Your string that contains !!! will be breaking it:

Serial.println("Ended !!!");

Simple solution: don't use so many exclamation marks.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.