Hello,
I warn in advance, I am not very experimented with the arduino environment.
Anyway, I have this code;
#include <Adafruit_MotorShield.h>
#include “utility/Adafruit_MS_PWMServoDriver.h”</adafruit_motorshield.h></wire.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor1 = AFMS.getStepper(300, 1);
Adafruit_StepperMotor *myMotor2 = AFMS.getStepper(300, 2);
boolean motorRunning = false;
unsigned long motorStartMillis;
unsigned long motorRunMillis = 180000;
int delaylegnth = 7;
void setup() {
//start serial connection
Serial.begin(9600);
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
// Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(“Stepper test!”);
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
myMotor1->setSpeed(100); // 10 rpm
}
void loop(){
//read the pushbutton value into a variable
int sensorVal = digitalRead(2);
sensorVal == LOW;
int delayL = 200;
if (sensorVal == LOW) {
Serial.println(“Minutes ++”);
//myMotor1->step(1640, BACKWARD, DOUBLE);
for (int i=0; i <= 10; i++){
myMotor1->step(147, BACKWARD, DOUBLE);
//analogWrite(PWMpin, i);
delay(delayL);
}
Serial.println(“Hours ++”);
myMotor1->step(1615, FORWARD, DOUBLE);
//myMotor2->step(1600, BACKWARD, DOUBLE);
myMotor2->step(220, FORWARD, DOUBLE);
}
else {
//Serial.println(“Double coil steps”);
myMotor1->step(0, FORWARD, DOUBLE);
myMotor1->step(0, BACKWARD, DOUBLE);
}
}
Instead of running the stepper 147 steps for 10 times (with delay between each time), I’d like to run for 1 second precisly and then a delay of 5 minutes for example. How could I run the stepper for a certain amount of time instead of steps? I know, steps are meant to be precise but … anyway.
OR
How could I start a timer as soon as the stepper motor starts it’s steps?
Anyone?
Thank you!
Sorry if it’s not so clear…