asterix
asterix

Reputation: 11

delay 10 secons is increasing arduino

Why the delay of 10 seconds is not constant value, it is increasing ?

I am using arduino nano version 3. I set 9600 bps

void loop() {
      serialPrint("Saaabbb--hghgE");
}
void serialPrint(String message){
  Serial.println(millis());
  Serial.println(message);
  delay(10000);
}

OUTPUT

0
Saaabbb--hghgE
10000
Saaabbb--hghgE
20000
Saaabbb--hghgE
30001
Saaabbb--hghgE
40001
Saaabbb--hghgE
50001
Saaabbb--hghgE
60002
Saaabbb--hghgE
70003
Saaabbb--hghgE
80004
Saaabbb--hghgE
90004
Saaabbb--hghgE
100004
Saaabbb--hghgE
110005
Saaabbb--hghgE
120006
Saaabbb--hghgE
130007
Saaabbb--hghgE
140007
Saaabbb--hghgE
150007

Upvotes: 0

Views: 264

Answers (2)

Vincent Guttmann
Vincent Guttmann

Reputation: 293

Yeah it's just the time needed to process your command. I don't know your project, but since my ones never needed the accuracy of a millisecond, I think you can just ignore it.

Upvotes: 0

Tzashi
Tzashi

Reputation: 83

The extra 1 added every couple of commands is the delay caused by actually processing your code. Serial.println(millis()) takes time to complete so the total time is process time + your added delay.

For example:

void loop() {
      serialPrint("Saaabbb--hghgE");
}
void serialPrint(String message){
  Serial.println(millis()); //takes 0.5millis (for example)
  Serial.println(message);  //takes 0.5millis (for example)
  delay(10000); //takes 10000millis
}

Therefore total time from millis() is 10001.

Upvotes: 1

Related Questions