#include <AccelStepper.h>
const int stepPin1 = 4;
const int directionPin1 = 3;
const int enablePin = 2;
const int stepPin2 = 5;
const int directionPin2 = 6;
const int lim_1 = 7;
const int lim_2 = 8;
AccelStepper stepper1(AccelStepper::DRIVER, stepPin1, directionPin1);
AccelStepper stepper2(AccelStepper::DRIVER, stepPin2, directionPin2);
unsigned long dist = 300;
unsigned long dist2 = 300;
int home = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int led = 13;
int lim1 = 0;
int lim2 = 0;
void setup() {
// put your setup code here, to run once:
stepper1.setEnablePin(enablePin);
stepper1.enableOutputs();
stepper1.setMaxSpeed(200000);
stepper1.setSpeed(150000);
stepper1.setAcceleration(200);
stepper2.setEnablePin(enablePin);
stepper2.enableOutputs();
stepper2.setMaxSpeed(200000);
stepper2.setSpeed(150000);
stepper2.setAcceleration(200);
pinMode(led, OUTPUT);
pinMode(lim_1, INPUT_PULLUP);
pinMode(lim_2, INPUT_PULLUP);
Serial.begin(9600);
stepper1.setCurrentPosition(0);
stepper2.setCurrentPosition(0);
}
void loop() {
lim1 = digitalRead(lim_1);
lim2 = digitalRead(lim_2);
if(lim1 == LOW){
stepper1.moveTo(dist);
stepper2.moveTo(dist2);
stepper1.run();
stepper2.run();
d = stepper1.isRunning();
}
while(d == 1){
stepper1.run();
stepper2.run();
c = stepper1.distanceToGo();
e = stepper1.acceleration();
Serial.print("Distance To Go = ");
Serial.print(c);
Serial.print(", Stepper 1 Running = ");
Serial.print(d);
Serial.print(", Stepper 1 Acceleration = ");
Serial.println(e);
break;
}
}