Jack-TW

Arduino Stepper 28BJY-48

Jan 31st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <Stepper.h>
  2. #define STEPS_PER_MOTOR_REVOLUTION 32   //定義馬達解析度
  3. #define STEPS_PER_OUTPUT_REVOLUTION 32 * 64  //2048  //定義馬達輸出解析度
  4. Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11); //設定要輸出的IC腳位
  5.  
  6. int  Steps2Take;//轉幾度變數
  7. int stpperSpeed=800; //設定轉數變數
  8. void setup()
  9. {
  10.     small_stepper.setSpeed(stpperSpeed); //設定轉動速度
  11. }
  12. void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
  13. {
  14.   Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION ;
  15.   small_stepper.step(Steps2Take); //開始轉動~
  16.  
  17.   delay(1000);
  18.   Steps2Take  =  - STEPS_PER_OUTPUT_REVOLUTION; //將要轉幾度的數值變成負值,讓步進馬達反轉
  19.   small_stepper.step(Steps2Take);
  20.   delay(1000);
  21.  
  22.  
  23. }/* --(end main loop )-- */
  24.  
  25. /* ( THE END ) */
Add Comment
Please, Sign In to add comment