PaulS says:
@Cybernetician
What is going to happen after the Arduino has been running for 10 seconds in your code?
Aqualize Says:
Yes that one only works the first iteration. I haven't compiled this code to test (to the Arduino C++ variant have do...while... loops?).
long quitTime;
void loop () {
quitTime = millis () + 10000;
do {
// Do stuff
} while (millis () < quitTime);
quitTime = millis () + 2000;
do {
// Do other stuff
} while (millis() < quitTime);
}
Remember that it won't interrupt the execution and jump out of a loop, so to make it work you can't have too much code (execution time wise "much") in there. Say that in the second step you have code which takes 1.5 second to run. Then it will exit the loop 3 seconds after it started. But if you have code that only takes 10 ms to run, well you may overshoot with a few ms but that is probably okay.
@Cybernetician
What is going to happen after the Arduino has been running for 10 seconds in your code?void loop(){
while (millis() < 10000) {
LoopA();
}
while (millis() < 2000) {
LoopB();
}
}
Ooops. what a big mistake tomorrow i post right one now i am late
thanks PaulS.
Need to minus time of loopA, loopB, and other statements execution time for near to perfect result.
#include "Timer.h"
Timer t;
bool lpA = true;
bool lpB = false;
int loopAEvent;
int loopBEvent;
void setup()
{
Serial.begin(9600);
loopAEvent = t.every(10000, loopBFlag);
}
void loop()
{
t.update();
if(lpA==true)
{
Serial.println("LOOPA");
}
if(lpB==true)
{
Serial.println("LOOPB");
}
}
void loopBFlag()
{
t.stop(loopAEvent);
lpA=false;
lpB=true;
loopBEvent = t.every(2000, loopAFlag);
}
void loopAFlag()
{
t.stop(loopBEvent);
lpA=true;
lpB=false;
loopAEvent = t.every(10000, loopBFlag);
}