int M1APin=14;
int M1BPin=27;
int M2APin=26;
int M2BPin=25;
int SPDPin=15;
int dutyCycle = 50; // 占空比为50%
void setup() {
// put your setup code here, to run once:
pinMode(M1APin,OUTPUT);
pinMode(M1BPin,OUTPUT);
pinMode(M2APin,OUTPUT);
pinMode(M2BPin,OUTPUT);
pinMode(SPDPin,OUTPUT);
ledcSetup(0, 5000, 10); //通道0, 5KHz,10位解析度
ledcAttachPin(SPDPin, 0); //pin25定义为通道0的输出引脚
ledcWrite(0, dutyCycle * 10); // 设置PWM占空比,范围为0-10230
//digitalWrite(M1APin,HIGH);
//digitalWrite(M1BPin,LOW);
digitalWrite(M1APin,LOW);
digitalWrite(M1BPin,HIGH);
//digitalWrite(M2APin,HIGH);
//digitalWrite(M2BPin,LOW);
digitalWrite(M2APin,LOW);
digitalWrite(M2BPin,HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
}