You could use millis()... the blink without delay sketch is the other hint.. and get the answer from DofunctionA
Doc