I'm currently looking to do the same thing, I'm assuming you don't want the loop running for power reasons otherwise you could just sit in a while loop waiting for a certain input. If this is the case I would start by looking here, this is the approach I'm probably going to take.