delay, but without delay.

J-M-L:
Millis does not work the way you wrote it. It’s the rest of the code that performs the expected time management. Programming requires precision.

Historically, the word precision belongs to the field of "Instrument Design", and it is used in conjunction with accuracy. For example: measuring instruments used in the research field should be both precise and accurate.

In practical programming, is it really possible to maintain precision?

My history lessons go a bit beyond that... historically it comes from latin præcisio (cutting short) and used in Middle French (ca. 1400-1600) Age. Precision was the quality of being precise

in English According to a dictionary

precision noun
pre·​ci·​sion | \ pri-ˈsi-zhən
the quality or state of being precise

precise adjective
pre·​cise | \ pri-ˈsīs
1 : exactly or sharply defined or stated
2 : minutely exact
3 : strictly conforming to a pattern, standard, or convention
4 : distinguished from every other

I used it in the sens of “ strictly conforming to a pattern, standard, or convention”

J-M-L:
I used it in the sens of “ strictly conforming to a pattern, standard, or convention”

Cool. :slight_smile:

This thread has everything. Etymology, metrology, and a whole lot of very poor advice about how blocking code is better than blocking code.

We are bumping the thread until OP decides to come back :wink:

GypsumFantastic:
This thread has everything. Etymology, metrology, and a whole lot of very poor advice about how blocking code is better than blocking code.

...with a side-order of word salad.

groundFungus:
Show some real code to illustrate the usage of a while loop used with millis().

This code is used as a non blocking delay of 1000 ms.

unsigned int previous;
previous = millis();
while(millis() - previous <= 1000)
{
//Just nothing here. It does nothing here.
}

It will wait for 1000 ms.

ArnavPawarAA:
This code is used as a non blocking delay of 1000 ms.

unsigned int previous;

previous = millis();
while(millis() - previous <= 1000)
{
//Just nothing here. It does nothing here.
}




It will wait for 1000 ms.

Try with unsigned long...

And it is blocking the loop and won’t do anything if you don’t put any statement to execute within the while...

Another ridiculous thread that could've been solved on the first reply with reference to a simple library. Install it via the Libraries Manager, take a mental note for further posts like this, and refer to the lib's cpp file if you have any questions on the theory behind non-blocking timing for Arduinos.

Example Sketch:

#include "FireTimer.h"

FireTimer msTimer;
FireTimer usTimer;

void setup()
{
  Serial.begin(115200);

  msTimer.begin(1000);
  usTimer.begin(1000000, MICRO_SECONDS);
}

void loop()
{
  if(msTimer.fire())
    Serial.println("ms");

  if(usTimer.fire())
    Serial.println("us");
}

Power_Broker:
Another ridiculous thread that could've been solved on the first reply with reference to a simple library.

There is no need for a library.. even if it is yours and especially if it is to advertise useless (ridiculous?) rollover management

 	// Handle overflow
	if (currentTime < timeBench)
		timeDiff = (UL_MAX - timeBench) + currentTime;
	else
		timeDiff = currentTime - timeBench;

	// Determine if enough time has passed
	if (timeDiff >= period)

(And discutable use case for passing by reference since you take a copy anyway)

J-M-L:
Try with unsigned long...

And it is blocking the loop and won’t do anything if you don’t put any statement to execute within the while...

Sorry, that code should be an unsigned long.

But delay() blocks the processes and millis() used like that doesn't block the background processes running in the Arduino.

..Arnav

ArnavPawarAA:
But delay() blocks the processes and millis() used like that doesn't block the background processes running in the Arduino.

What background processes?

GypsumFantastic:
What background processes?

All of them, of course. :smiling_imp:

GypsumFantastic:
What background processes?

The garbage collector may be?
:slight_smile:

@ Arnav
I mentioned that already- when you don’t know you’d be better off refraining from trying to boost your post count or at the very minimum - because it’s a free speech place - write in a way that shows you are offering hypothesis.
Most of what you write is approximative at best and often plain wrong. There are enough fake news and alternate truth those days, please don’t bring that here. Thx

(deleted)

There's a yield() in there that I didn't know about.

That means that a while loop-based DIY pause function blocks more than the standard delay() does, yeah?

GypsumFantastic:
There's a yield() in there that I didn't know about.

that's for being safe across multiple architectures (multi-core) that require some other processes to do their own cooking (ESP for example where a watchdog will come bark at you).

On AVR, yield() normally does nothing; it's an empty or non-existent function

/**
 * Empty yield() hook.
 *
 * This function is intended to be used by library writers to build
 * libraries or sketches that supports cooperative threads.
 *
 * Its defined as a weak symbol and it can be redefined to implement a
 * real cooperative scheduler.
 */
static void __empty() {
 // Empty
}
void yield(void) __attribute__ ((weak, alias("__empty")));

the optimizer will likely get rid of the call if not implemented.