极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12673|回复: 0

基于arduino的步进电机

[复制链接]
发表于 2012-4-13 12:52:42 | 显示全部楼层 |阅读模式
是这样的,正转3圈,反转3圈,然后就停止勒,如何实现循环啊~~!
[code=cpp]int dirPin = 6;
int stepperPin = 5;
int switch1  = 14;
int switch2 = 15;
int value;

void setup() {
  pinMode(dirPin, OUTPUT);
  pinMode(stepperPin, OUTPUT);
  pinMode(switch1, INPUT);
  pinMode(switch2, INPUT);
}

void step(boolean dir,int steps){
  digitalWrite(dirPin,dir);
  for(int i=0; i < steps; i ++) {
    digitalWrite(stepperPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepperPin, LOW);
    delayMicroseconds(500);

    // speed control
    delayMicroseconds(100);
  }
}

void loop(){
  value = digitalRead(switch1);
  if (HIGH == value) {
    step(true,1600 * 3);
  }

  value = digitalRead(switch2);
  if (HIGH == value) {
    step(false,1600 * 3);
  }
}
[/code]
这是程序
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-20 11:06 , Processed in 0.046391 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表