ESP32 最小 Arduino PWM 输出示例 (PlatformIO)
esp32_pwm_example.cpp
#include <Arduino.h>
#include <driver/ledc.h>
void setup() {
Serial.begin(115200);
ledcSetup(LEDC_CHANNEL_0, 10000 /* Hz */, 12);
ledcAttachPin(GPIO_NUM_14, LEDC_CHANNEL_0);
ledcWrite(LEDC_CHANNEL_0, 2048); // 50%
}
void loop() {
// 如何将占空比更改为 25% 的示例
ledcWrite(LEDC_CHANNEL_0, 1024);
}Check out similar posts by category:
Arduino, ESP8266/ESP32, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow