during this action an LED flashes
How many times do you think the LED will flash in the time it takes the pin to go HIGH?
and the other limit switch does the same
What other limit switch? You said you have ONE limit switch.
If the limit switches stop the motor without you having to do anything, you REALLY need to post a schematic showing how they are wired.