Reprogram Marlin to assign endstop pins to arbitrary tasks [Arduino Mega]
Apparently, given one 


has already enabled USE_&lt;AXIS&gt;_PLUG (for example 
&lt;AXIS&gt; = XMIN) in Marlin's Configuration.h,
one can add an additional define (for example &lt;AXIS&gt;_ENDSTOP_CUSTOM) in
Configuration.h and 
make this block the else statement in an
&lt;AXIS&gt;_ENDSTOP_CUSTOM existence check, with the positive case being your
arbitrary task.


The function that gets executed in the standard case in the linked block is PROCESS_ENDSTOP, so cloning it would be a good starting point to make a PROCESS_ENDSTOP_CUSTOM task, too.