hsilva
1
I need to have this loop run for 10 minutes and than wait 50 minutes. It needs to do this over and over.
can someone show me how i could do this?
#include <AccelStepper.h>
#define FULLSTEP 4
#define HALFSTEP 8
#define motorPin1 8 // Blue - 28BYJ48 pin 1
#define motorPin2 9 // Pink - 28BYJ48 pin 2
#define motorPin3 10 // Yellow - 28BYJ48 pin 3
#define motorPin4 11 // Orange - 28BYJ48 pin 4
#define motorPin5 4 // Blue - 28BYJ48 pin 1
#define motorPin6 5 // Pink - 28BYJ48 pin 2
#define motorPin7 6 // Yellow - 28BYJ48 pin 3
#define motorPin8 7 // Orange - 28BYJ48 pin 4
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(FULLSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
void setup() {
// 1 revolution Motor 1 CW
//stepper1.setMaxSpeed(1000.0);
//stepper1.setAcceleration(50.0);
//stepper1.setSpeed(200);
//stepper1.moveTo(2048);
// 1 revolution Motor 2 CCW
stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(100.0);
stepper2.setSpeed(400);
stepper2.moveTo(-1024);
//Change direction at the limits
//if (stepper1.distanceToGo() == 0)
//stepper1.moveTo(-stepper1.currentPosition());
}
void loop() {
if (stepper2.distanceToGo() == 0)
stepper2.moveTo(-stepper2.currentPosition());
stepper2.run();
}
something like this maybe:
#include <AccelStepper.h>
#define FULLSTEP 4
#define HALFSTEP 8
#define motorPin1 8 // Blue - 28BYJ48 pin 1
#define motorPin2 9 // Pink - 28BYJ48 pin 2
#define motorPin3 10 // Yellow - 28BYJ48 pin 3
#define motorPin4 11 // Orange - 28BYJ48 pin 4
#define motorPin5 4 // Blue - 28BYJ48 pin 1
#define motorPin6 5 // Pink - 28BYJ48 pin 2
#define motorPin7 6 // Yellow - 28BYJ48 pin 3
#define motorPin8 7 // Orange - 28BYJ48 pin 4
#define RUN 10
#define WAIT 50
#define TOTAL_TIME RUN+WAIT
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(FULLSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
uint8_t counter = 0, servo_stop = 0;
unsigned long oldtime
void setup() {
// 1 revolution Motor 1 CW
//stepper1.setMaxSpeed(1000.0);
//stepper1.setAcceleration(50.0);
//stepper1.setSpeed(200);
//stepper1.moveTo(2048);
// 1 revolution Motor 2 CCW
stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(100.0);
stepper2.setSpeed(400);
stepper2.moveTo(-1024);
//Change direction at the limits
//if (stepper1.distanceToGo() == 0)
//stepper1.moveTo(-stepper1.currentPosition());
oldtime = millis();
}
void loop() {
if (counter < RUN) {
if (stepper2.distanceToGo() == 0) stepper2.moveTo(-stepper2.currentPosition());
stepper2.run();
servo_stop = 0;
}
else if (servo_stop == 0) { //<----put the right command(s) here to stop the servo at desire position
stepper2.stop();
servo_stop = 1;
}
//increments counter every minute. counter loops 0-59
if (millis() - oldtime < 60000) {
counter = (counter + 1) % TOTAL_TIME;
oldtime = millis();
}
}
please note that code is untested and I do not know what are you intention when servo is to stop. please update the code accordingly.
hope that helps.
Robin2
3
The demo Several Things at a Time illustrates the use of millis() to manage timing. It may help with understanding the technique.
Have a look at Using millis() for timing. A beginners guide if you need more explanation.
...R