Take a look at this web page. It shows how to use the Compressor object built into WPILib. It will automatically run the compressor when the pressure switch shows low pressure.
Be sure to not put the code in a loop since the Compressor class will start up a thread that will do all the checking in the background.
http://wpilib.screenstepslive.com/s/...for-pneumatics
Brad