#include <AccelStepper.h>
#define pul1 17
#define pul2 0
#define dir1 16
#define dir2 4
AccelStepper stepper(1,pul1,dir1);
AccelStepper stepper2(1,pul2,dir2);
void setup() {
stepper.setMaxSpeed(200); // Maximum speed (steps per second)
stepper.setAcceleration(500); // Acceleration (steps per second^2)
stepper.moveTo(0);
stepper2.moveTo(0);
stepper2.setMaxSpeed(200); // Maximum speed (steps per second)
stepper2.setAcceleration(500); // Acceleration (steps per second^2)
}
void loop() {
if (stepper.distanceToGo() == 0) {
delay(2000);
// If the motor has reached the target, move to the next position
static int positions[] = {200, -200, 500, -500}; // Array of positions to move to
static int currentPosIndex = 0;
stepper.move(positions[currentPosIndex]);
// Update to the next position in the array
currentPosIndex = (currentPosIndex + 1) % (sizeof(positions) / sizeof(positions[0]));
}
// Run the motor to the target position
stepper.run();
if (stepper2.distanceToGo() == 0) {
delay(2000);
// If the motor has reached the target, move to the next position
static int _positions[] = {-200, 200, -500, 500}; ; // Array of positions to move to
static int _currentPosIndex = 0;
stepper2.move(_positions[_currentPosIndex]);
// // Update to the next position in the array
_currentPosIndex = (_currentPosIndex + 1) % (sizeof(_positions) / sizeof(_positions[0]));
};
// // Run the motor to the target position
stepper2.run();
}