Making somthing run for X amount of time

Then try my take on the subject
State Machine