Conteo y resta de flancos, control de motor ¿que solución usar?

Your current code tests to see if the sensor is HIGH which is what is causing your problem.
What you need is to test when the sensor BECOMES HIGH. In other words when it changes state.

See the State Change detection example in the IDE under File > Examples > 02.Digital > StateChangeDetection