Go Down

Topic: why need a delay between readings? (Read 950 times) previous topic - next topic

reading_he

hello, everyone:

when i learn the tutorial in

https://www.arduino.cc/en/Tutorial/AnalogReadSerial

https://www.arduino.cc/en/Tutorial/DigitalReadSerial

both example code have a line of code of delay(1) and i cannot understand the comments clearly. The stability for/of what?

lloyddean

#1
Feb 17, 2016, 04:21 am Last Edit: Feb 17, 2016, 04:24 am by lloyddean
<https://www.arduino.cc/en/Reference/AnalogRead>

Perhaps some are using the delay to filter noise from the signal?

holmes4

There is no delay in the link you gave. And there would be no point in one!

Mark

Koepel

#3
Feb 17, 2016, 05:00 am Last Edit: Feb 17, 2016, 05:01 am by Koepel
On my screen they both have a delay :o
The delay is in the tutorial but on in the reference.

reading_he, the delay of 1ms is not really needed for "stability". However, sending a lot of data to the serial monitor with an Arduino Leonardo is not very nice, it might clog up the serial communication and uploading a sketch might fail. Therefor I would use a delay of 100ms to slow down the sketch.

The digitalRead() and analogRead() themself don't need a delay at all. It is only about the amount of data send to the serial monitor.

nickgammon

Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

larryd

No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.


jurs

both example code have a line of code of delay(1) and i cannot understand the comments clearly.
Me, too.

In both code examples the line containing "delay()" is not of any use.
It can be replaced by an empty line, deleted line, or you can comment it out easily without seeing a difference.

Both code examples have "Serial @9600 Baud" as a bottleneck which is slowing down the loop() function more than 1ms. So an additional 1ms delay() will not make any difference. It's a waste in both code examples.

Robin2

#8
Feb 17, 2016, 10:06 am Last Edit: Feb 17, 2016, 10:08 am by Robin2
both example code have a line of code of delay(1) and i cannot understand the comments clearly. The stability for/of what?
Without a short delay() the Arduino would be sending a huge amount of data to the Serial Monitor. To be honest I would have delay(500) so I only get a new value twice per second.

analogRead() only takes about 100 microseconds and digitalRead() maybe 5 microseconds

I agree that the comment in the code is not adequate.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up