So I know that in one section of a code one can write to a pin, then later on, read from that same pin.
I have a dc motor on a linear actuator and the way it works is when you put 12V to the DC motor the actuator travels in one direction, then when it reaches its end of travel it just stops, even with power still connected to the terminals of the motor. I want to use a relay module (octocoupled) that when the pin I assign goes high, it closes the circuit between 12V from a tractor battery and the forward terminals of a DC motor controller. Aside from running that command through a timer setup, or adding a limit switch, is there any way that I can read that stop from the actuator and use that to tell my mega2560 to send that pin LOW? Or do I just setup and run a timer command for the duration of the travel?