Im using a very simple code to run my stepper motors using an arduino uno and a cnc shield. The code runs and turns the motors but I need them to turn forward and backwards. Im sure im missing something simple please help. If you look on line 46 to 49 I reversed the HIGH, LOW function think this would reverse the polarity but apparently I am wrong.
const int StepX = 2;
const int DirX = 5;
const int StepY = 3;
const int DirY = 6;
//const int StepZ = 4;
//const int DirZ = 7;
void setup() {
pinMode(StepX,OUTPUT);
pinMode(DirX,OUTPUT);
pinMode(StepY,OUTPUT);
pinMode(DirY,OUTPUT);
// pinMode(StepZ,OUTPUT);
// pinMode( DirZ,OUTPUT);
}
void loop() {
digitalWrite(DirX, HIGH); // set direction, HIGH for clockwise, LOW for anticlockwise
digitalWrite(DirY, HIGH);
// digitalWrite(DirZ, HIGH);
for(int x = 0; x<200; x++) { // loop for 200 steps 1
digitalWrite(StepX,HIGH);
delayMicroseconds(500);
digitalWrite(StepX,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<20; x++) { // loop for 20 steps
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
digitalWrite(StepY,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<20; x++) { // loop for 20 steps
digitalWrite(StepY,LOW);
delayMicroseconds(500);
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<200; x++) { // loop for 200 steps 2
digitalWrite(StepX,HIGH);
delayMicroseconds(500);
digitalWrite(StepX,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<20; x++) { // loop for 20 steps
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
digitalWrite(StepY,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<20; x++) { // loop for 20 steps
digitalWrite(StepY,LOW);
delayMicroseconds(500);
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<200; x++) { // loop for 200 steps 3
digitalWrite(StepX,HIGH);
delayMicroseconds(500);
digitalWrite(StepX,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<20; x++) { // loop for 20 steps
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
digitalWrite(StepY,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<20; x++) { // loop for 20 steps
digitalWrite(StepY,LOW);
delayMicroseconds(500);
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<500; x++) { // loop for 500 steps LONG CUT HOLDER
digitalWrite(StepX,HIGH);
delayMicroseconds(500);
digitalWrite(StepX,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<20; x++) { // loop for 20 steps
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
digitalWrite(StepY,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<250; x++) { // loop for 250 steps LONG CUT HOLDER
digitalWrite(StepX,HIGH);
delayMicroseconds(500);
digitalWrite(StepX,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<20; x++) { // loop for 20 steps COMING OFF HOLDER CUT
digitalWrite(StepY,LOW);
delayMicroseconds(500);
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<166; x++) { // loop for 250 steps GOING BACK FOR SECOND HOLDER CUT
digitalWrite(StepX,LOW);
delayMicroseconds(500);
digitalWrite(StepX,HIGH);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<40; x++) { // loop for 20 steps SETTING UP FOR LAST 2ND CUT FOR HOLDER
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
digitalWrite(StepY,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<80; x++) { // loop for 80 steps LAST 2ND CUT FOR HOLDER HOLDER
digitalWrite(StepX,HIGH);
delayMicroseconds(500);
digitalWrite(StepX,LOW);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
for(int x = 0; x<50; x++) { // loop for 50 steps COMING OFF OF LAST CUT FINISHING
digitalWrite(StepY,LOW);
delayMicroseconds(500);
digitalWrite(StepY,HIGH);
delayMicroseconds(500);
}
delay(1000); // delay for 1 second
}