Skip to main content

Module ledc

Module ledc 

Source
Expand description

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

Interface to the LED Control (LEDC) peripheral

§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§

config
Types for configuring the LED Control peripheral

Structs§

CHANNEL0
CHANNEL1
CHANNEL2
CHANNEL3
CHANNEL4
CHANNEL5
LEDC
The LED Control device peripheral
LedcDriver
LED Control driver
LedcTimerDriver
LED Control timer driver
LowSpeed
Low speed mode for the LED Control peripheral
PwmError
TIMER0
TIMER1
TIMER2
TIMER3

Enums§

Resolution

Traits§

LedcChannel
LED Control peripheral output channel
LedcTimer
LED Control peripheral timer
SpeedMode
Speed mode for the LED Control peripheral The ESP32 supports two speed modes: low and high speed All others support only low speed mode.