//Pin configuration
int dirPinA = 8;
int stepPinA = 9;
int dirPinB = 6;
int stepPinB = 7;
//Changing Direction
bool dirA = LOW;
bool dirB = LOW;
//Changing the number of overall cycles and steps in each cycle
int i=0;
int cycle=1; //change this variable to edit the number of cycles
int step=200; //number of step per cycle
//delay
int us=50; //delaymicroseconds
int ms=10; //delay (in miliseconds)
void setup()
{
Serial.begin(9600);
pinMode(stepPinA, OUTPUT);
pinMode(dirPinA, OUTPUT);
pinMode(stepPinB, OUTPUT);
pinMode(dirPinB, OUTPUT);
digitalWrite(dirPinA, dirA);
digitalWrite(dirPinB, dirB);
}
void loop(){
moveAB(step, stepPinA, step, stepPinB);
delay(1000);
i+=1;
if(i==cycle) exit(0);
}
void moveAB(long nStepA, int stepPinA, long nStepB, int stepPinB){
long nstep = 1;
while (nstep <= nStepA || nstep <= nStepB){
nstep++;
digitalWrite(stepPinA, HIGH);
digitalWrite(stepPinB, HIGH);
delayMicroseconds(us);
digitalWrite(stepPinA, LOW);
digitalWrite(stepPinB, LOW);
delayMicroseconds(us);
delay(ms);
}
}