This sounds like something the timer and interrupt could be used for. How to actually do it though is totally greek to me.