#include <AccelStepper.h>
const int stepPin1 = 4;
const int directionPin1 = 3;
const int enablePin = 2;
const int lim_1 = 7;
const int lim_2 = 8;
AccelStepper stepper1(AccelStepper::DRIVER, stepPin1, directionPin1);
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);
pinMode(led, OUTPUT);
pinMode(lim_1, INPUT_PULLUP);
pinMode(lim_2, INPUT_PULLUP);
Serial.begin(9600);
stepper1.setCurrentPosition(0);
}
void loop() {
lim1 = digitalRead(lim_1);
lim2 = digitalRead(lim_2);
if(lim1 == LOW and lim2 == HIGH){
while(stepper1.currentPosition() < 300){
stepper1.moveTo(dist);
stepper1.run();
}
}
if (lim2 == LOW and lim1 == HIGH){
while(stepper1.currentPositiom() > 0){
stepper1.moveTo(0);
stepper1.run();
}
}
}