const int E1 = 3; ///<Motor1 Speed
const int M1 = 4; ///<Motor1 Direction
void M1_advance(char Speed) ///<Motor1 Advance
{
digitalWrite(M1,LOW);
analogWrite(E1,Speed);
}
void M1_back(char Speed){
digitalWrite(M1,HIGH);
analogWrite(E1,Speed);
}
int v = 50;
String data;
void setup() {
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
Serial.begin(115200);
//pinMode(pz,INPUT);
}
void loop() {
if(Serial.available()>0){
data = Serial.readString();
Serial.println(data);
Serial.println(v);
}
int v = data.toInt();
M1_advance(v);
Serial.println(v);
}
串口输入后直接进行了数据类型转换,串口调速会有延时,暂不知道啥原因