#define STEP0_PUL 18 //步进0_PUL
#define STEP0_DIR 19 //步进0_DIR
#define STEP0_EAN 21 //步进0_EAN
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(STEP0_PUL, OUTPUT);
pinMode(STEP0_DIR, OUTPUT);
pinMode(STEP0_EAN, OUTPUT);
digitalWrite(STEP0_EAN,LOW); //打开
digitalWrite(STEP0_DIR,LOW); //打开
}
String inString = ""; // string to hold input
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available() > 0) {
int inChar = Serial.read();
if (isDigit(inChar)) {
// convert the incoming byte to a char and add it to the string:
inString += (char)inChar;
}
// if you get a newline, print the string, then the string's value:
if (inChar == '\n') {
Value=inString.toInt();
Serial.print("Value:");
Serial.println(Value);
if(Value>0){
digitalWrite(STEP0_DIR,LOW);
}
else{
digitalWrite(STEP0_DIR,HIGH);
}
for(int i=0;i<Value;i++){
digitalWrite(STEP0_PUL,HIGH);
delay(50);
digitalWrite(STEP0_PUL,LOW);
delay(50);
}
// clear the string for new input:
inString = "";
}
}
delay(10);
}