Module esp_idf_svc::hal::ledc

source ·
Expand description

LED Control peripheral (which also creates PWM signals for other purposes)

Interface to the LED Control (LEDC) peripheral

This is an initial implementation supporting the generation of PWM signals but no chrome and spoilers like fading.

§Examples

Create a 25 kHz PWM signal with 75 % duty cycle on GPIO 1

use esp_idf_hal::ledc::{config::TimerConfig, Channel, LedcDriver, LedcTimerDriver, Timer};
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::prelude::*;

let peripherals = Peripherals::take().unwrap();
let timer_driver = LedcTimerDriver::new(peripherals.ledc.timer0, &TimerConfig::default().frequency(25.kHz().into()));
let mut driver = LedcDriver::new(peripherals.ledc.channel0, timer_driver, peripherals.pins.gpio1)?;

let max_duty = driver.get_max_duty()?;
driver.set_duty(max_duty * 3 / 4)?;

See the examples/ folder of this repository for more.

Modules§

  • Types for configuring the LED Control peripheral

Structs§

Enums§

Traits§