Using an external ADC.

Make all of the IO's digital.

This may get me in trouble but I am going to refer you to a Basic Stamp document.

http://www.parallax.com/dl/docs/books/edu/ic.pdf

Goto the section "Experiment #4: Continuous Process Control"

The Basic Stamp is built around a PIC but does not have ADC. The code is close enough to understand what is going on.

The above "Experiment #4: Continuous Process Control" is using a LM34 and a n ADC 0831.

If I told you how to do it, it would just be the same thing as in the document, almost. There are other good ideas there too.