hysteresis of some sort

What else is wrong?

I don't know - you're the one with the hardware and the debug prints.
You do have debug prints, don't you?