我必须停止步进电机一定次数(一整圈),并以延迟作为停止参数。假设我的要求是停止电机 20 次,这样我的延迟值应该均匀分布在这个数字之间(20 )完成一个旋转。我为这些停止(20)使用了一个for循环,但我得到了超过20个。我的arduino代码如下所示,其中8000是一圈的步数:
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
// step one revolution in one direction:
void loop() {
int noi=20;// set the no of images here
for(int i=0;i<=noi;i++){
delay(8000/noi);
}
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
}