其實Arduino自己就有步進電機的庫函數,如果不想自己編就直接調用就行(兩相四拍的)
幫助文件:http://arduino.cc/en/Reference/Stepper
用法:在菜單欄中:程序-》導入庫-》stepper
就加入了#include
可參加自帶例子程序:文件-》示例-》stepper下。
速度設置為120rpm時丟步,100時可用。說明效果不如前面自己寫的程序,奇怪。
#include
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,9,10,11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
// Serial.println("counterclockwise");
// myStepper.step(-stepsPerRevolution);
// delay(500);
}
下一步:多個步進電機如何控制?時間是否夠用