專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> Arduino >> 瀏覽文章

Arduino UNo 通過LM298n控制步進(jìn)電機(jī)(3)

作者:goingxu   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2014年04月21日   【字體:

 

其實(shí)Arduino自己就有步進(jìn)電機(jī)的庫函數(shù),如果不想自己編就直接調(diào)用就行(兩相四拍的)

幫助文件:http://arduino.cc/en/Reference/Stepper

示例:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=3512&reltid=3143&pre_thread_id=0&pre_pos=6&ext

 

用法:在菜單欄中:程序-》導(dǎo)入庫-》stepper

就加入了#include

可參加自帶例子程序:文件-》示例-》stepper下。

 

速度設(shè)置為120rpm時(shí)丟步,100時(shí)可用。說明效果不如前面自己寫的程序,奇怪。

#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);
}

 

下一步:多個(gè)步進(jìn)電機(jī)如何控制?時(shí)間是否夠用
 

關(guān)閉窗口

相關(guān)文章