Added simple state machine

Seems to work, but probably needs some tuning to better account
for noise and associated value fluctuations.
Adjusted active level to be lower

Looks like the hysteresis is a bit wider. Might need to adjust it
some more after testing.