esp-idf-hal/examples/ledc_simple.rs
ivmarkov 2af4695aac
Remove Peripheral/PeripheralRef (#529)
* Remove Peripheral/PeripheralRef

* Make ADC unit and channel structs more readable by avoiding const generics

* Remove unused parameter

* fix forgotten reference to the old ADCU syntax

* Mention that we have removed the prelude module

* try_into methods for changing the pin type
2025-09-03 14:13:32 +03:00

34 lines
885 B
Rust

use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::ledc::*;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::units::*;
fn main() -> anyhow::Result<()> {
esp_idf_hal::sys::link_patches();
println!("Configuring output channel");
let peripherals = Peripherals::take()?;
let mut channel = LedcDriver::new(
peripherals.ledc.channel0,
LedcTimerDriver::new(
peripherals.ledc.timer0,
&config::TimerConfig::new().frequency(25.kHz().into()),
)?,
peripherals.pins.gpio4,
)?;
println!("Starting duty-cycle loop");
let max_duty = channel.get_max_duty();
for numerator in [0, 1, 2, 3, 4, 5].iter().cycle() {
println!("Duty {numerator}/5");
channel.set_duty(max_duty * numerator / 5)?;
FreeRtos::delay_ms(2000);
}
loop {
FreeRtos::delay_ms(1000);
}
}