reading a sensor and using an if statement

I think you might do well to study how the blinkWithoutDelay works...