How to calculate intervals and execute an action at the specified time?

Have you taken a look at the servo library?