I am working in a project where I need to call more than 1 functions actually 4 functions using a single millis()
Here is the code below.
unsigned long then = 0;
void loop(){
unsigned long now = millis();
if(now-then >=0){
Serial.println("Function 1 called");
}else if(now-then>=2000){
Serial.println("Function 2 called");
}else if(now-then>=4000){
Serial.println("Function 3 called");
}else if(now-then>=6000){
Serial.println("Function 4 called");
Serial.println("The end");
then = now;
}
}
All the functions above gets run successfully but not in a proper sequence.
The running sequence of the functions seem to be very improper and random.
The 'function 1' gets executed in a proper sequence and timing but rest of the others are making a messy output.
How can I fix it please?
Thanks.
else
? why only onethen
?