初探Arduino,(步进电机MP28GA+ULN2003)Setpper扩展库的使用-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 6040|回复: 0

初探Arduino,(步进电机MP28GA+ULN2003)Setpper扩展库的使用

[复制链接]
发表于 2013-1-21 22:47 | 显示全部楼层 |阅读模式
刚起步,新手一枚,有错请指正啊。


Arduino uno 今天刚到,迫不及待的插上原来51用的步进电机试一下。。
不过。。貌似直接调用Setpper库无效...
无奈看头文件...
[mw_shl_code=c,true]   switch (thisStep) {
      case 0:    // 1010
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, HIGH);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 1:    // 0110
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      digitalWrite(motor_pin_3, HIGH);
      digitalWrite(motor_pin_4, LOW);
      break;
      case 2:    //0101
      digitalWrite(motor_pin_1, LOW);
      digitalWrite(motor_pin_2, HIGH);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, HIGH);
      break;
      case 3:    //1001
      digitalWrite(motor_pin_1, HIGH);
      digitalWrite(motor_pin_2, LOW);
      digitalWrite(motor_pin_3, LOW);
      digitalWrite(motor_pin_4, HIGH);
      break;[/mw_shl_code]

改为

[mw_shl_code=c,true]case 0:
     digitalWrite(motor_pin_1, HIGH);  
     digitalWrite(motor_pin_2, LOW);
     digitalWrite(motor_pin_3, LOW);
     digitalWrite(motor_pin_4, HIGH);
        break;
case 1:
     digitalWrite(motor_pin_1, HIGH);  
     digitalWrite(motor_pin_2, LOW);
     digitalWrite(motor_pin_3, LOW);
     digitalWrite(motor_pin_4, LOW);
        break;  
        case 2:
     digitalWrite(motor_pin_1, HIGH);  
     digitalWrite(motor_pin_2, HIGH);
     digitalWrite(motor_pin_3, LOW);
     digitalWrite(motor_pin_4, LOW);
        break;  
case 3:
     digitalWrite(motor_pin_1, LOW);  
     digitalWrite(motor_pin_2, HIGH);
     digitalWrite(motor_pin_3, LOW);
     digitalWrite(motor_pin_4, LOW);
        break;
case 4:
     digitalWrite(motor_pin_1, LOW);  
     digitalWrite(motor_pin_2, HIGH);
     digitalWrite(motor_pin_3, HIGH);
     digitalWrite(motor_pin_4, LOW);
        break;  
case 5:
     digitalWrite(motor_pin_1, LOW);  
     digitalWrite(motor_pin_2, LOW);
     digitalWrite(motor_pin_3, HIGH);
     digitalWrite(motor_pin_4, LOW);
        break;   
case 6:
     digitalWrite(motor_pin_1, LOW);  
     digitalWrite(motor_pin_2, LOW);
     digitalWrite(motor_pin_3, HIGH);
     digitalWrite(motor_pin_4, HIGH);
        break;  
case 7:
     digitalWrite(motor_pin_1, LOW);  
     digitalWrite(motor_pin_2, LOW);
     digitalWrite(motor_pin_3, LOW);
     digitalWrite(motor_pin_4, HIGH);
        break;  
default:
     digitalWrite(motor_pin_1, LOW);  
     digitalWrite(motor_pin_2, LOW);
     digitalWrite(motor_pin_3, LOW);
     digitalWrite(motor_pin_4, LOW);
   break; [/mw_shl_code]
[mw_shl_code=c,true]stepMotor(this->step_number % 7);[/mw_shl_code]

之后就正常了

测试代码
[mw_shl_code=c,true]#include <Stepper.h>
#define STEPS 300
Stepper s(STEPS,8,9,10,11);
//////////////////////////////////////////////////////////////////////////////
void setup() {
s.setSpeed(100);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){
  s.step(50);
}[/mw_shl_code]

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

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-27 22:44 , Processed in 0.072003 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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