So I have been trying to write a code where I use the millis() function to print the milliseconds of on-time of the board using Serial. But the condition is I want to stop printing the value once it reaches 10 seconds (10000ms).

I have been trying to use the exit() function but I get no output then.


void setup()

  Serial.begin(9600);          //  setup serial


void loop()


unsigned long timer1;







  • What do you imagine exit() is supposed to do in an embedded system? – Ignacio Vazquez-Abrams Dec 15 '15 at 19:08
  • 3
    exit() is probably a bad idea in a bare-metal embedded system unless you know for a fact how the environment will respond. Consider either an infinite while(1); loop explicit in your own code, or shutting down the processor. Make sure to wait until the serial output buffer is empty before shutting down or disabling interrupts, or you may see your messages truncated. – Chris Stratton Dec 15 '15 at 19:08
  • Where do you suppose exit() would exit to in a microcontroller? Your desk? – Majenko Dec 16 '15 at 0:18

The AVR library documentation for exit() is great help. It explains that the interrupts are turned off and an infinite loop is entered. As the interrupts get turned off the last characters in the Serial buffer are not transmitted.

You can use Serial.flush() to wait for the transmission to complete before calling exit().


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.