Hi guys, i am a noob at this, but i am trying a simple project.
i have two steppers, a smaller one is attached to the shaft of the larger one, the larger one turns the smaller motor to two different angles, when its over a certain angle the smaller one spins.
i am trying to add a delay to each of the larger ones end points, which i will control with a potentiometer, for now i just need to get it working.
I need to use millis() instead of delay so i can run the smaller one on and off.
If someone could point me in the right direction that would be great.
#include <AccelStepper.h>
long previousTime = 0;
long delaywait = 0;
AccelStepper stepDrive(1, 10, 11); //Head Motor
AccelStepper glassDrive(1, 5, 6); //Glass motor
void setup() {
stepDrive.setMaxSpeed(300);
stepDrive.setAcceleration(20000);
stepDrive.setCurrentPosition(0);
glassDrive.setMaxSpeed(200);
glassDrive.setAcceleration(20000);
glassDrive.setCurrentPosition(0);
glassDrive.setSpeed(2000);
}
void loop() {
unsigned long currentMillis = millis();
if (stepDrive.currentPosition() == 0) //send head drive to 300
{
stepDrive.moveTo(300);
}
if (stepDrive.currentPosition() == 300 ) //send head drive back to load
{
int newtime = currentMillis + (1000); // THIS IS THE UNKNOWN BIT I WANT IT TO DELAY FOR 1s BEFORE RETURNING
if (currentMillis == newtime)
{
stepDrive.moveTo(0);
}
}
if(stepDrive.currentPosition() > 150) //spool motor up as it passes 150
{
glassDrive.runSpeed();
}
stepDrive.run();
}