I have a function that needs to execute every n microseconds.
If I have
Void loop{
delay(200);
My function;
}
And myfucntion takes 100ms to complete then each loop will be 300ms. Not good.
How can I use the millis function to ensure the delay is taking into consideration the time it takes for myfucntion to complete?
Basically I need myfunction to start every 200ms regardless of the time it takes myfunction to complete. (obviously if myfunctiom takes more than 200ms I'll have problems but it's usually taking 2-3 to complete.
If you want to execute MyFunction immediately the first time loop() is called instead of waiting for THRESHOLD ms, then initialize lastTime to millis() - THRESHOLD instead in setup().