如何用arduino控制步进电机
2个回答
展开全部
例子程序:
#include
const int stepsPerRevolution = 400; // 对于两相四线的电机,一般步距角是1.8度,这里如果是四拍就写200,八拍就写400
// initialize the stepper library on pins 8 through 11:
Stepper myStepper1(stepsPerRevolution, 4,5,6,7); //两个电机分别占四个脚
Stepper myStepper2(stepsPerRevolution, 8,9,10,11);
void setup() {
// set the speed at 60 rpm:
myStepper1.setSpeed(60);
myStepper2.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
int r;
for(int i=0; i<400;)
{
r= myStepper1.stepOneStep(0);
myStepper2.stepOneStep(1);//括号中的参数是方向,0和1代表不同转动方向
if(r==2) i++;
}
delay(500);
}
#include
const int stepsPerRevolution = 400; // 对于两相四线的电机,一般步距角是1.8度,这里如果是四拍就写200,八拍就写400
// initialize the stepper library on pins 8 through 11:
Stepper myStepper1(stepsPerRevolution, 4,5,6,7); //两个电机分别占四个脚
Stepper myStepper2(stepsPerRevolution, 8,9,10,11);
void setup() {
// set the speed at 60 rpm:
myStepper1.setSpeed(60);
myStepper2.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
int r;
for(int i=0; i<400;)
{
r= myStepper1.stepOneStep(0);
myStepper2.stepOneStep(1);//括号中的参数是方向,0和1代表不同转动方向
if(r==2) i++;
}
delay(500);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询