https://www.youtube.com/watch?v=GyEa5MPJw_A
匯入Stepper程式庫
草稿碼->匯入程式庫->管理程式庫
在上方搜尋輸入"Stepper",選擇第一個進行安裝,安裝完成就可使用
https://openhome.cc/Gossip/CodeData/mBlockArduino/mBlockArduino16.html
#include <Stepper.h>
const int stepsPerRevolution = 2048;
// 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(5);
// 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);
}
留言
張貼留言