End stop switch

hi,

can any one help me out to make me code for cnc shield for end switch. i found some of on the internet but once the end stop (x) pressed both x axis and y axis are stopping.

i will appreciate your kind help.

Your post was MOVED to its current location as it is more suitable.

Do you think it would help if we could see your code?

(This isn't an installation and troubleshooting issue - please use the flag icon below to ask a moderator to move this topic to a more suitable section?)

this is the code i have tried, but this is stopping both x any y motors.
#define EN 8
#define X_DIR 5
#define X_STP 2

int delayTime=15; //Delay between each pause (uS)
long int stps=12800;// microsteps per revolution with 1/32 microstepping
const int limitPin = 9; //enable limitPin

void step(boolean dir, byte dirPin, byte stepperPin, long int steps)

{

digitalWrite(dirPin, dir);

delay(100);

for (long int i = 0; i < steps; i++) {

digitalWrite(stepperPin, HIGH);

delayMicroseconds(delayTime); 

digitalWrite(stepperPin, LOW);

delayMicroseconds(delayTime); 

}
}

void setup() {
pinMode(X_DIR, OUTPUT);
pinMode(X_STP, OUTPUT);
pinMode(EN, OUTPUT);
pinMode(limitPin, INPUT);
digitalWrite(EN, LOW);

}

void loop() {
while( digitalRead(limitPin) == HIGH){
step(false, X_DIR, X_STP, stps);
if( digitalRead(limitPin) == LOW)
{
step(true, X_DIR, X_STP, stps);
}
}
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

This code doesn't show any Y motor. Only X_DIR and X_STP. The Y motor should not be moving at all unless it is wired to the X pins. If it IS wired to the X pins there is no way to stop the X motor without also stopping the 'Y' motor connected to the same pins.