Converting analog to digital

I'll look into this code if I find I need a hysteresis. Thanks!