// Include the AccelStepper library:
#include <AccelStepper.h>
#define dirPin1 8
#define stepPin1 9
#define dirPin2 10
#define stepPin2 11
#define motorInterFaceType 1
AccelStepper stepper = AccelStepper(motorInterFaceType, stepPin1, dirPin1);
AccelStepper pusher = AccelStepper(motorInterFaceType, stepPin2, dirPin2);
void setup() {
// Set the maximum speed in steps per second:
stepper.setMaxSpeed(1000);
pusher.setMaxSpeed(1000);
Serial.begin(9600);
}
void loop() {
// Set the current position to 0:
stepper.setCurrentPosition(0);
pusher.setCurrentPosition(0);
while(stepper.currentPosition() != 100)
{
stepper.setSpeed(400);
stepper.runSpeed();
}
delay(1000);
stepper.setCurrentPosition(0);
while(stepper.currentPosition() != -100)
{
stepper.setSpeed(-400);
stepper.runSpeed();
}
delay(5000);
stepper.setCurrentPosition(0);
while(pusher.currentPosition() != 200)
{
pusher.setSpeed(690);
pusher.runSpeed();
}
delay(1000);
}
pusher.setCurrentPosition(0);
while(pusher.currentPosition() != -200)
{
pusher.setSpeed(-690);
pusher.runSpeed();
}
delay(5000);
pusher.setCurrentPosition(0);
}
When i run the i get error message exit status 1
Compilation error: 'pusher' does not name a type
Can anyone help me please. Trying to control 2 motors on 2 A4988 drivers independently. I can control them individually but i am struggle to use them in the same program.
If you use the IDE autoformat tool (ctrl-t or Tools, Auto format) you can see where you have a misplaced curly bracket (}) that closes loop early. The code after the misplaced bracket is outside of any function which results in the error.
// Include the AccelStepper library:
#include <AccelStepper.h>
#define dirPin1 8
#define stepPin1 9
#define dirPin2 10
#define stepPin2 11
#define motorInterFaceType 1
AccelStepper stepper = AccelStepper(motorInterFaceType, stepPin1, dirPin1);
AccelStepper pusher = AccelStepper(motorInterFaceType, stepPin2, dirPin2);
void setup()
{
// Set the maximum speed in steps per second:
stepper.setMaxSpeed(1000);
pusher.setMaxSpeed(1000);
Serial.begin(9600);
}
void loop()
{
// Set the current position to 0:
stepper.setCurrentPosition(0);
pusher.setCurrentPosition(0);
while (stepper.currentPosition() != 100)
{
stepper.setSpeed(400);
stepper.runSpeed();
}
delay(1000);
stepper.setCurrentPosition(0);
while (stepper.currentPosition() != -100)
{
stepper.setSpeed(-400);
stepper.runSpeed();
}
delay(5000);
stepper.setCurrentPosition(0);
while (pusher.currentPosition() != 200)
{
pusher.setSpeed(690);
pusher.runSpeed();
}
delay(1000);
//} extra } closes loop() early
pusher.setCurrentPosition(0);
while (pusher.currentPosition() != -200)
{
pusher.setSpeed(-690);
pusher.runSpeed();
}
delay(5000);
pusher.setCurrentPosition(0);
}
The AccelStepper library has a class called MultiStepper to move motors simultaneously. Unfortunately it does not use acceleration so speed is limited.
I find the MobaTools stepper library easier to use. The movement functions work in the background without having to call a run function (runSpeed) to make them move.
Please describe what you want the code to do, in detail.