//Downloaded the AceelStepper Library to control more than one motor :D
#include <AccelStepper.h>
//Define step constant...4=full and 8=half
#define FULLSTEP 4
AccelStepper Top_motor (FULLSTEP,4, 6, 5, 7);
AccelStepper Lower_motor (FULLSTEP, 10, 12, 11, 13);
//This is the internal timer for Arduino
int timer;
void setup() {
//Timer
Serial.begin(9600);
millis();
//Motor stuff
Serial.begin(9600);
//Motor 1 (Top) ...max speed is 1000...
Top_motor.setMaxSpeed(1000.0);
Top_motor.setAcceleration(50.0);
Top_motor.setSpeed(400);
Top_motor.moveTo(4000);
//Motor 2 (Lower) NOITCE how the negative will move it counterclockwise if I wanted (on 2038)
//4000 is the max amount of steps which is like about 15 secs at a speed of 200...accel of 50.
Lower_motor.setMaxSpeed(1000.0);
Lower_motor.setAcceleration(50.0);
Lower_motor.setSpeed(400);
Lower_motor.moveTo(4000);
}
void loop() {
//Time begins
timer = millis();
//Move the top motor counterclockwise but do not move the bottom motor... the 4000 is on average 15 secs
//setCurrentPosition(0) as a restart? between code or maybe add stop();
if (timer > 0) {
Top_motor.moveTo(4000*-1);
Lower_motor.move(0);
Top_motor.run();
Lower_motor.run();
}
//Do not move the top motor but move the bottom motor clockwise...after two seconds to let it have time to stop and restart
if (timer > 25000) {
Top_motor.move(0);
Lower_motor.moveTo(4000);
Top_motor.run();
Lower_motor.run();
}
//reset
//Move the top motor clockwise but do not move the bottom motor
if (timer > 45000) {
Top_motor.moveTo(4000);
Lower_motor.setCurrentPosition(0);
Top_motor.run();
Lower_motor.run();
}
//Do not move the top motor but move the bottom motor counterclock
if (timer > 65000) {
Top_motor.moveTo(0);
Lower_motor.runToNewPosition(-Lower_motor.currentPosition());
Top_motor.run();
Lower_motor.run();
}
//Move the top motor counterclockwise but do not move the bottom motor
if (timer > 85000) {
Top_motor.runToNewPosition(4000*-1);
Lower_motor.moveTo(0);
Top_motor.run();
Lower_motor.run();
}
//Stops moving
if (timer > 105000) {
Top_motor.stop();
Top_motor.disableOutputs();
Lower_motor.stop();
Lower_motor.disableOutputs();
Top_motor.run();
Lower_motor.run();
}
}