Hello.Ι thought the below function ,so I have 1 question and I want to help me,please…
Does the below function works like a delay or like millis() {I ask because I confused because of the do while condition}
To wit,that function delay all the program or only one part of it???
void callMillis(unsigned long x)
{
unsigned long presentMILLIS = millis();
do
{
}
while (millis() - presentMILLIS <= x);
}
For example:
void loop()
{
digitalWrite(led,HIGH);
callMillis(1000);
digitalWrite(led,LOW);
callMillis(1000);
}
Yes ,but if in loop-function for example call AND another function (that blink a led every 0.1 sec. with millis()) does the function that blink the led affects from the other one(by calling callMillis) ?
arduiNICK:
Yes ,but if in loop-function for example call AND another function (that blink a led every 0.1 sec. with millis()) does the function that blink the led affects from the other one(by calling callMillis) ?
Am I clear?
You are not on a multi-processor / multi-core architecture so when the processor is busy doing something, other parts of your code are not being executed... so how would you have a function that blinks the led and callMillis() executing at the same time.
My problem is:
I want to delay(with millis) only one part of the program for only one time and then to continue below, but I did many attempts and nothing.Can you help about it?
for example:
void some()
{
//I do something here…
Here I want to delay this function for one time (like delay(200))
//continue to do something else…
}
void loop()
{
some();
}
But when I do it ,millis() doesn’t work and the program starts from the beginning…
Yes ,but I want to do it for one time without delay ,because at the same time I want to run and another function
and delay will stop anything ...
Have you understand my problem?
Besides learning how to use millis and if instead of while, you should have a look at state machines.
Or look at the “doing several things at a time” tutorial.
if I did not mess it up, the program will wait 3 seconds in the setup, then you’ll see millis() being blasted to the console very quickly with every second the message “next second” being inserted and after 2 seconds then only the “next second” should be displayed