求大神帮助一下
程序思路:有三个电机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 }
|