Need Help! AccelStepper library

Thread Starter

royashley99

Joined Nov 20, 2021
43
How can i control 2 stepper motors with 2 potentiometers like you do with servos.
This is the code i have but both stepper motors turn when i move the one potentiometer but when i turn the other one none of them turn.

Im using 28BYJ-48 with Uln2003 driver boards.


#include <AccelStepper.h>


AccelStepper stepper1(4, 4, 6, 5, 7);
AccelStepper stepper2(4, 8, 10, 9, 11);

#define potpin1 A0
#define potpin2 A1

void setup()
{
stepper1.setMaxSpeed(500);
stepper1.setAcceleration(500);

stepper2.setMaxSpeed(500);
stepper2.setAcceleration(500);
}

void loop() {

static int last_analog_in1;
int analog_in1 = analogRead(0);
if (analog_in1 != last_analog_in1)
{
stepper1.moveTo(analog_in1);
last_analog_in1 = analog_in1;
}
stepper1.run();

static int last_analog_in2;
int analog_in2 = analogRead(1);
if (analog_in2 != last_analog_in2)
{
stepper2.moveTo(analog_in2);
last_analog_in2 = analog_in2;
}
stepper2.run();
}
 
Top