As far as I can tell, the code I wrote should do exactly what you are trying to accomplish, and what I have said several times without contradiction or correction from you.
Again:
Please show us the complete program you are currently talking about in a new post.
If you used my code suggestions, did you carefully verify the polarity of the sensor readings and make any necessary adjustments?
I got the rest of my life here. You only delay progress by failing to answer our questions and requests.
a7