Hello guys!
My idea is to use the timer and counter to achieve 5 minutes but without stop the read main code and when it reach the 5 minutes it will generate a flag and stop the timer and counter.
any suggestions??
Hello guys!
My idea is to use the timer and counter to achieve 5 minutes but without stop the read main code and when it reach the 5 minutes it will generate a flag and stop the timer and counter.
any suggestions??
Function millis() is available to you .. use it.
The BlinkWithoutDelay example will show you how to use millis() for timing.
yes, I already did a routine that count one minute but didn't work as I planned.
My idea is to use a library to execute a parallel code.
for example:
my parallel code executed by the library would be like the code below:
int Soneca::Timer(int timeToCountDown)
{
int timeToCountDown1 = 120;
unsigned long lastTime = 0;
int bool_flag_SLEEP_TIME;
unsigned long currTime = millis();
while(bool_flag_SLEEP_TIME!=0)
{
if(currTime - lastTime > 1000) // If a second has passed...
{
lastTime = currTime;
timeToCountDown1--;
}
if (timeToCountDown1==0)
{
bool_flag_SLEEP_TIME =1;
}
else bool_flag_SLEEP_TIME =0;
}
return bool_flag_SLEEP_TIME;
}
but when I use other code to get the variable=1 in the finish of the process.
int bool_flag_SLEEP_TIME = Soneca1.Timer(300);
Serial.println(bool_flag_SLEEP_TIME);
Which library are you intending to use? The usual arduino OS doesn't support multithreading. There are some multithreading things around, but AFAIK they are all experimental.
Everyone else does "parallel" processes by time slicing. Each "process" is a function which always returns quickly. If a function needs to time something, then it uses millis() or micros() and keeps track of what state the thing it is timing is in.