It is exactly what I had in mind, it's better if you use the analog inputs, because the IR foto-transistor works linearly according to the amount of infrared light at it's base, ie the voltage at its output will increase or decrease linearly.
For simple applications the digital input can be used, but for more precise applications you must use the analog port and check its values through the software or make a better interface for digital input.