good day,
I'm kinda new to programming with the Arduino and now i'm working on a new home project where you have a closet that spins through 2 stepper motors that kinda looks like this : shelfs-jepg hosted at ImgBB — ImgBB
But now I'm running in a little issue, I'm using the accelstepper library were i can set the position for the stepper motors which is really working well but but what is happening is this lets say your current position is shelf 1 and you want to go to shelf 6 what it does is this: (shelf 1,2,3,4,5,6) it does 5 steps,
instead i want is: (shelf 1,6) just take 1 step, so my problem is i have no clue how to do this.
here is my code:
//for now i will use only 1 stepper motor
//and I'm sorry if my code looks absolute garbage
#include <AccelStepper.h>
AccelStepper stepperN(1, 9, 8); // pin 9 = step, pin 8 = direction
//the position from the shelfs
int shelf1 =0;
int shelf2 =1000;
int shelf3 =2000;
int shelf4 =3000;
int shelf5 =4000;
int shelf6 =5000;
void setup() {
Serial.begin(9600);
Serial.println("type shelf1/6 ");
}
void loop() {
stepperN.run();
while(Serial.available() > 0 ){
String str = Serial.readString();
if(str.indexOf("shelf1") > -1){
stepperN.setAcceleration(50); stepperN.setMaxSpeed(313); stepperN.moveTo(shelf1); stepperN.run();
}
else if(str.indexOf("shelf2") > -1){
stepperN.setAcceleration(50); stepperN.setMaxSpeed(313); stepperN.moveTo(shelf2); stepperN.run();
}
else if(str.indexOf("shelf3") > -1){
stepperN.setAcceleration(50); stepperN.setMaxSpeed(313); stepperN.moveTo(shelf3); stepperN.run();
}
else if(str.indexOf("shelf4") > -1){
stepperN.setAcceleration(50); stepperN.setMaxSpeed(313); stepperN.moveTo(shelf4); stepperN.run();
}
else if(str.indexOf("shelf5") > -1){
stepperN.setAcceleration(50); stepperN.setMaxSpeed(313); stepperN.moveTo(shelf5); stepperN.run();
}
else if(str.indexOf("shelf6") > -1){
stepperN.setAcceleration(50); stepperN.setMaxSpeed(313); stepperN.moveTo(shelf6); stepperN.run();
}
}
}
I hope someone is able to help me.