#include <AccelStepper.h>
#define pul1 2
#define dir1 3
#define pul2 4
#define dir2 5
#define pul3 6
#define dir3 7
AccelStepper stepper1(AccelStepper::DRIVER, pul1, dir1);
AccelStepper stepper2(AccelStepper::DRIVER, pul2, dir2);
AccelStepper stepper3(AccelStepper::DRIVER, pul3, dir3);
// void setup() {
// // put your setup code here, to run once:
// pinMode(pul1, OUTPUT);
// pinMode(dir1, OUTPUT);
// stepper1.setMaxSpeed(400.0);
// stepper1.setAcceleration(200.0);
// stepper2.setMaxSpeed(200);
// stepper2.setAcceleration(100);
// stepper3.setMaxSpeed(200);
// stepper3.setAcceleration(100);
// }
// void loop() {
// // put your main code here, to run repeatedly:
// stepper1.moveTo(0);
// stepper1.moveTo(200);
// stepper1.moveTo(600);
// }
/*NOTES:
Items named "VCC" and GND are the external power suitable for the stepper requirements, + connected to VMOT
The A4988 driver "VCC" pin is connected to the arduino/attiny 5v
*/
// #include <AccelStepper.h>
// const byte motStep = 2;
// const byte motDir = 3;
int mm = 0;
float mmSteps = 200; // Arbitrary number of steps per mm of axis travel - Change to suit
// AccelStepper stepper(AccelStepper::DRIVER, motStep, motDir);
void setup() {
pinMode(pul1, OUTPUT);
pinMode(dir1, OUTPUT);
pinMode(pul2, OUTPUT);
pinMode(dir2, OUTPUT);
pinMode(pul3, OUTPUT);
pinMode(dir3, OUTPUT);
stepper1.setMaxSpeed(400.0);
stepper1.setAcceleration(200.0);
stepper2.setMaxSpeed(400.0);
stepper2.setAcceleration(200.0);
stepper3.setMaxSpeed(400.0);
stepper3.setAcceleration(200.0);
}
// Single function to move the motor x number of mm (steps per mm * mm requested)
void motMove1(int mm) {
if(stepper1.distanceToGo() == 0){
delay(50); // Short delay between moves
stepper1.moveTo(mm * mmSteps);
}
stepper1.run();
}
void motMove2(int mm) {
if(stepper2.distanceToGo() == 0){
delay(50); // Short delay between moves
stepper2.moveTo(mm * mmSteps);
}
stepper2.run();
}
void motMove3(int mm) {
if(stepper3.distanceToGo() == 0){
delay(50); // Short delay between moves
stepper3.moveTo(mm * mmSteps);
}
stepper3.run();
}
void loop() {
motMove1(2); // Go to 2mm (based on steps/mm defined above)
motMove1(0); // Go to 0mm
motMove2(2); // Go to 2mm (based on steps/mm defined above)
motMove2(0); // Go to 0mm
motMove3(2); // Go to 2mm (based on steps/mm defined above)
motMove3(0); // Go to 0mm
}