6 条评论

  • @ 2025-6-21 14:41:23
    const int ledPin1 = 26;
    //const int ledPin2 = 27;
    //PWM参数定义
    const int freq = 5000;         //频率
    const int ledChannel_1 = 1;    //PWM通道 0~15//const int ledChannel_2 = 2;    //PWM通道 0~15
    const int resolution = 8;      //PWM的分辨率 0~255之间
    void setup() {
      // Setup timer and attach timer to a led pin
      ledcSetup(ledChannel_1, freq, resolution);  //初始化PWM通道参数//ledcSetup(ledChannel_2, freq, resolution);  //初始化PWM通道参数
      ledcAttachPin(ledPin1, ledChannel_1);       //将通道1和GPIO26关联//ledcAttachPin(ledPin2, ledChannel_2);       //将通道2和GPIO27关联
    }
    void loop() {
      for(int i=0;i<=255;i+=5)           //从暗到亮
      {
        ledcWrite(ledChannel_1,i);      //向通道1写入指定值
        delay(20);  
      }
      for(int i=255;i>=0;i-=5)           //从亮到暗
      {
        ledcWrite(ledChannel_1,i);      //向通道1写入指定值
        delay(20);  
      }
    }
    
    
    • @ 2025-6-21 14:16:54

      • @ 2025-6-21 14:13:16

        • @ 2025-6-21 14:12:41

          • @ 2025-6-21 14:12:29

            • @ 2025-6-21 14:12:19

              • 1