中断控制电机反向转动
2013-12-16 13:32
344 查看
[code] [code]
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
int stepsPerRevolution = 200;
int pbIn = 5;
Stepper myStepper(stepsPerRevolution, 9,7,8,6);
void setup(){
attachInterrupt(pbIn,stateChange,RISING);
// 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);
}
void stateChange()
{
stepsPerRevolution = -stepsPerRevolution;
}
[/code]
[/code]
不知道为什么,当行程开关按下的时间不一样时,会出现这样一种怪现象:电机先反向转了一圈,然后又恢复了原来的方向,有点诡异。而且电机对开关的响应还是迟钝,大概这个也是Arduino的缺点,不过肯定有优化的方法,也可能是我对电机的库函数的理解不对!
相关文章推荐
- Xcode编写C/C++程序
- 导入项目出现乱码的解决办法
- yacc语法笔记
- 心理学分析编程能力的四种境界
- 一个库搞定各种分享--ShareSDK
- 如何判断Linux是否适合你
- 第十六周上机项目4-奇数因子
- js 截取url
- Hadoop集群(第5期)_Hadoop安装配置
- 将IplImage* 保存为图片的问题之jpg还是bmp
- java四舍五入
- 显示pdf等
- 11个遇事有水平的处理方法
- seo技术第一天:SEO是什么
- Cocos2d-X游戏【泰然网《跑酷》】JS到C++移植3:游戏主菜单界面的实现
- SWT事件的四种写法
- C语言 &运算
- C# js调用后台方法
- 如何读懂JSHint & JSLint 配置选项及报错信息
- iOS app支付宝接口调用