
电路原理运行代码const int stepPin3; const int dirPin4; void setup() { // put your setup code here, to run once: pinMode(stepPin, OUTPUT);//设置引脚为输出模式 pinMode(dirPin, OUTPUT);//设置引脚为输出模式 } void loop() { // put your main code here, to run repeatedly: digitalWrite(dirPin, HIGH);//电机沿着一定方向旋转 for(int i0;i200;i)//输入200个脉冲转动一圈 { digitalWrite(stepPin, HIGH); delayMicroseconds(500); digitalWrite(stepPin, LOW); delayMicroseconds(500); } delay(1000); digitalWrite(dirPin, LOW);//电机向相反方向转动 for(int i0;i800;i)//输入800个脉冲转动4圈 { digitalWrite(stepPin, HIGH); delayMicroseconds(500); digitalWrite(stepPin, LOW); delayMicroseconds(500); } delay(1000); }