const int freq = 5000;      //PWM的频率
const int ledChannel = 0;  //PWM的通道
const int resolution = 13;  //PWM的分辨率,0~255
void setup() {
  // 设置通道0的PWM出处参数
  ledcSetup(ledChannel,freq,resolution);
  ledcAttachPin(23,ledChannel);   //将通道0与GPI23建立关联
  ledcAttachPin(4,ledChannel);    //将通道0与GPI04建立关联
  
}

void loop() {
  for(int i = 0 ; i < 255; i+=5) //循环实现由暗变亮
  {
    ledcWrite (ledChannel,i);  //向通道0写入指定值
    delay (50);
  }
  for(int i = 255; i > 0; i-=5)
  {
    ledcWrite(ledChannel,i);
    delay(50);
   
  }
}