Adafruit Motor Shield
函式庫安裝步驟
1.先下載Library,下載完畢後新增資料夾名為:AFMotor,將檔案解壓縮至該資料夾內
2.將AFMotor資料夾放入Arduino路徑內的libraries資料夾內,EX:C:\Program Files\Arduino\libraries
3.從新啟動Arduino後,會在File->Example發現AFMotor
範例程式:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <AFMotor.h> //呼叫該函式庫 | |
AF_DCMotor motor(2, MOTOR12_64KHZ); // AF_DCMotor 變數名稱(第幾個馬達控制, 頻率) | |
// Motor1 & Motor2 有這幾個頻率: | |
// MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ, MOTOR12_1KHZ | |
// | |
// Motor3 & Motor4 有這幾個頻率: | |
// MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_1KHZ | |
// | |
void setup() { | |
Serial.begin(9600); // set up Serial library at 9600 bps | |
Serial.println("Motor test!"); | |
motor.setSpeed(200); // set the speed to 200/255 | |
} | |
void loop() { | |
Serial.print("tick"); | |
motor.run(FORWARD); // turn it on going forward | |
delay(1000); | |
Serial.print("tock"); | |
motor.run(BACKWARD); // the other way | |
delay(1000); | |
Serial.print("tack"); | |
motor.run(RELEASE); // stopped | |
delay(1000); | |
} |
沒有留言:
張貼留言