arduino控制三电机简单运动-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2377|回复: 0

arduino控制三电机简单运动

[复制链接]
发表于 2019-9-7 21:57 | 显示全部楼层 |阅读模式
求大神帮助一下
程序思路:有三个电机123,先让1动,然后23动,再让1动,再让23动。
问题:只有2.3电机动
代码:
#define PUL1 9
#define PUL 7
#define PUL2 5
#define DIR1 8
#define DIR 6
#define DIR2 4
void setup()
{
  pinMode(PUL1,OUTPUT);                                                                                    
  pinMode(PUL, OUTPUT);
  pinMode(PUL2, OUTPUT);
  pinMode(DIR1, OUTPUT);
  pinMode(DIR, OUTPUT);
  pinMode(DIR2, OUTPUT);
  Serial.begin(9600);
}
void loop()
{
digitalWrite(DIR2,LOW);
for(int x=0;x<6000;x++);
{
digitalWrite(PUL2,HIGH);
delayMicroseconds(500);
digitalWrite(PUL2,LOW);
delayMicroseconds(500);
}
delay(1000);
  digitalWrite(DIR1, HIGH);
  digitalWrite(DIR, LOW);
  for (int x = 0; x < 2000; x ++)         // 正向转X圈(2000脉冲)
{
    digitalWrite(PUL1, HIGH);
    digitalWrite(PUL, HIGH);
    delayMicroseconds(500);
    digitalWrite(PUL1, LOW);
    digitalWrite(PUL, LOW);
    delayMicroseconds(500);
  }
  delay(1000); // Delay for one second
digitalWrite(DIR2,HIGH);
for(int x=0;x<6000;x++);
{
digitalWrite(PUL2,HIGH);
delayMicroseconds(500);
digitalWrite(PUL2,LOW);
delayMicroseconds(500);
}
delay(1000);
  // Changes the rotation direction or rotates in opposite direction
  digitalWrite(DIR1, LOW);
  digitalWrite(DIR, HIGH);
  for (int x = 0; x < 6000; x ++)          // 反向转X圈(6000脉冲)
{
    digitalWrite(PUL1, HIGH);
    digitalWrite(PUL, HIGH);
    delayMicroseconds(500);       
    digitalWrite(PUL1, LOW);
    digitalWrite(PUL, LOW);
    delayMicroseconds(500);
}
  delay(2000);     //Delay for 2 seconds
}

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

本版积分规则

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

GMT+8, 2024-11-28 11:32 , Processed in 0.070151 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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