//PWM控制
int pwm1 = 21;
//管道esp32有16个管道,0-7为80hz 高速管道  8-16为低速管道
const int channel1 = 0;
//分辨率  2的8次方 256
const int resolution = 8;
//PWM频率
const int freq = 1000;
//初始值 49%
int PwmNow = 125;
//累加数
int fadeAmount = 5;  
void setup(void) {
pinMode(pwm1, OUTPUT);
  ledcSetup(channel1, freq, resolution);
  ledcAttachPin(pwm1, channel1);
  ledcWrite(channel1, PwmNow);
  pinMode(infrared1, INPUT_PULLUP);
  digitalWrite(infrared1, LOW);
}
void loop(void) {
  if(PwmNow<255){
      PwmNow = PwmNow + fadeAmount;
      ledcWrite(channel1, PwmNow);
      int temp=PwmNow*100/255;
      String tempStr=String(temp)+"%";
Serial.println(tempStr);
delay(1000);
  }


