0

If I add a delay for a few seconds, and then will the value given by millis () be equal just before and after delay?

Or to put it in other words, does the internal clock of Arduino stop during delay?

2

No, I cannot check it (no Arduino at hand), but afaik the clock always keeps counting, so if you perform a delay of 1 second, and diff millis() just before and after, it will be (slightly over) 1,000 (ms).

Note however, that the use of delay is discouraged and it is better to check millis() to perform the next state/command instead of a delay which prevents doing other tasks meanwhile. But the (internal) timer always keeps running.

Only during some deep sleep mode it might stop, but than a delay will not work neither. And when interrupts are disbled (see remark of Chris Stratton below).

  • 1
    You are missing the more common exception: time also stops incrementing when interrupts are disabled. – Chris Stratton Jun 11 '18 at 15:10
  • @ChrisStratton Thanks ... I added it in my answer. Also, I didn't know this although is seems very logical. – Michel Keijzers Jun 11 '18 at 15:52
3

Delay uses millis. It just waits examining millis until a certain time has passed.

Millis is driven by an interrupt. The only thing that stops it working is another interrupt (you can only have one interrupt executing at once), which is why you can't use delay in an interrupt.

  • 1
    Delay, millis, micros, etc, it's all one and the same. – Majenko Jun 11 '18 at 10:33
  • 1
    That's not quite right either - disabling interrupts outside of an ISR will also stop it. – Chris Stratton Jun 11 '18 at 15:11
  • 1
    Ok, Mr pedant. We all know you value your opinion. – Majenko Jun 11 '18 at 16:04
  • 1
    It's not a question of opinion, but of the misleadingly false use of the word "only" for something that is not in fact the only possibility. Normally an answer doesn't have to mention everything, but if it is going to use exclusive language, it does, otherwise readers can be mislead. For that matter, "borrowing" the utilized timer for some other custom purpose would break it, too. – Chris Stratton Jun 11 '18 at 16:18
  • 1
    You create a lot of useless nose on here you know. The users here don't need to know such levels of detail most of the time. Tailor the answer to the audience. – Majenko Jun 11 '18 at 16:59

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.