slvias2001 發表於 2021-8-20 13:52:01

如何給一個步進電機 完成一個迴圈後 即停止動做的指令??

新手求助 Arduino Uno+A4988+42步進電機 ,
小第寫了一個讓步進電機可以轉10圈的程序
以下是目前程序,不斷的循環迴圈~

請問要怎麼修改~才能讓不進電機完成一個迴圈後即停止的指令呢?
請大大門協助~非常感謝!!!

// A4988连接Arduino引脚号
const int dirPin = 2;// 方向引脚
const int stepPin = 3; // 步进引脚

// 电机每圈步数
const int STEPS_PER_REV = 200;

void setup() {

// Arduino控制A4988步进和方向的引脚为输出模式
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
// 设置电机顺时针旋转,LOW則為逆時針
digitalWrite(dirPin,HIGH);

// 电机慢速旋转X=2000代表轉10圈
for(int x = 0; x < 2000; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(2000);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(2000);
}

// 等待一秒
delay(5000);

}
頁: [1]
查看完整版本: 如何給一個步進電機 完成一個迴圈後 即停止動做的指令??