keeping the Arduino in a function for X time

Have you tried the blink without delay technique?