本帖最后由 xyp 于 2022-4-10 20:56 编辑
这是调试的代码
#define STEPPIN 9
#define DIRPIN 8
//方向位为8,脉冲位为9
void setup() {
pinMode(STEPPIN, OUTPUT);
pinMode(DIRPIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Enables the motor to move in a particular direction
Serial.println("Forward Begins");
digitalWrite(DIRPIN, HIGH);
// 正向转2圈(400脉冲)
for (int x = 0; x < 400; x ++) {
digitalWrite(STEPPIN, HIGH);
delayMicroseconds(500);
digitalWrite(STEPPIN, LOW);
delayMicroseconds(500);
}
Serial.println("Forward Ends");
delay(1000); // Delay for one second
// Changes the rotation direction or rotates in opposite direction
Serial.println("Backward Begins");
digitalWrite(DIRPIN, LOW);
// 反向转3圈(600脉冲)
for (int x = 0; x < 600; x ++) {
digitalWrite(STEPPIN, HIGH);
delayMicroseconds(500);
digitalWrite(STEPPIN, LOW);
delayMicroseconds(500);
}
Serial.println("Backward Ends");
delay(2000); //Delay for two seconds
}
|