How do I make my program not use CPU cycles when it's waiting for a cirtain event to occur (like input from a hardware port)?