User Tools

Site Tools


tutorials:arduino:stepper_motor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorials:arduino:stepper_motor [2014/02/27 21:36]
aaron
tutorials:arduino:stepper_motor [2014/02/28 10:20] (current)
sam
Line 9: Line 9:
  
 ===== Abstract ===== ===== Abstract =====
 +How to do this,please refer to [[http://​docs.cubieboard.org/​tutorials/​arduino/​controlling_led |light led]] and [[http://​docs.cubieboard.org/​tutorials/​arduino/​connecting|how to connect cubieboard and arduino]]
 +
 {{:​tutorials:​arduino:​照片_4.jpg|400}} {{:​tutorials:​arduino:​照片_4.jpg|400}}
 {{:​tutorials:​arduino:​照片_3.jpg|400}} {{:​tutorials:​arduino:​照片_3.jpg|400}}
Line 19: Line 21:
 #include <​Stepper.h>​ #include <​Stepper.h>​
  
-// 这里设置步进电机旋转一圈是多少步 
 #define STEPS 100 #define STEPS 100
  
-// attached to设置步进电机的步数和引脚 
 Stepper stepper(STEPS,​ 8, 9, 10, 11); Stepper stepper(STEPS,​ 8, 9, 10, 11);
  
-// 定义变量用来存储历史读数 
 int previous = 0; int previous = 0;
  
 void setup() void setup()
 { {
-  // 设置电机每分钟的转速为90步+
   stepper.setSpeed(90);​   stepper.setSpeed(90);​
 } }
Line 36: Line 35:
 void loop() void loop()
 { {
-  // 获取传感器读数 
   int val = analogRead(0);​   int val = analogRead(0);​
  
-  // 移动步数为当前读数减去历史读数+
   stepper.step(val - previous);   stepper.step(val - previous);
  
-  // 保存历史读数 
   previous = val;   previous = val;
-} 
-/* 
- * 步进电机跟随电位器旋转 
- * (或者其他传感器)使用0号模拟口输入 
- * 使用arduino IDE自带的Stepper.h库文件 
- */ 
- 
-#​include <​Stepper.h>​ 
- 
-//​ 这里设置步进电机旋转一圈是多少步 
-#​define STEPS 100 
- 
-//​ attached to设置步进电机的步数和引脚 
-Stepper stepper(STEPS,​ 8,​ 9,​ 10,​ 11);​ 
- 
-//​ 定义变量用来存储历史读数 
-int previous = 0;​ 
- 
-void setup() 
-{ 
-  //​ 设置电机每分钟的转速为90步 
-  stepper.setSpeed(90);​ 
-} 
- 
-void loop() 
-{ 
-  //​ 获取传感器读数 
-  int val = analogRead(0);​ 
- 
-  //​ 移动步数为当前读数减去历史读数 
-  stepper.step(val - previous);​ 
- 
-  //​ 保存历史读数 
-  previous = val;​ 
 } }
  
tutorials/arduino/stepper_motor.1393508211.txt.gz · Last modified: 2014/02/27 21:36 by aaron