I'll let Darrel help with the coding but, if you haven't used this sensor, you should be aware that decoupling its voltage supply line is critical (Figure 3 in the datasheet). Otherwise, it will be too noisy to make use of its output.