Need help programming IR sensor??

For class we have a project to make a robot. Our robot is going to be a forklift. The problem we have is that we are using an IR sensor where the fork is, so when an object is close enough it will start the motor where the lift is. Everything has to start at a push of a button. So for now we are using an LED in place of the motor, so that the LED lights up when it gets to a certain distance. But what happens is that we either have to keep pushing the button so the IR sensor gets different reads or hold the button down while moving the IR sensor. The LED lights up when the IR sensor has a value of 3 or greater but we are trying to get it so we only have to push the button once and the IR sensor is continuously reading until it gets to a certain value.

Set a flag when the button is pushed. Take readings if the flag is set. When the threshold is reached, clear the flag until the button is pushed again.