-
-
Save sirhcel/831b7ee3f53940676a4445c77407db36 to your computer and use it in GitHub Desktop.
Attempt of simple example for ledc driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use embedded_hal::{ | |
pwm::blocking::PwmPin, | |
delay::blocking::DelayUs, | |
}; | |
use esp_idf_hal::delay::Ets; | |
use esp_idf_hal::ledc::{ | |
config::TimerConfig, | |
Channel, | |
Timer, | |
}; | |
use esp_idf_hal::peripherals::Peripherals; | |
use esp_idf_hal::prelude::*; | |
use esp_idf_sys::EspError; | |
fn main() -> anyhow::Result<()> { | |
let peripherals = Peripherals::take().unwrap(); | |
let config = TimerConfig::default().frequency(25.kHz().into()); | |
let timer = Timer::new(peripherals.ledc.timer0, &config)?; | |
let mut channel = Channel::new(peripherals.ledc.channel0, &timer, peripherals.pins.gpio1)?; | |
let max_duty = channel.get_max_duty()?; | |
for numerator in [0, 1, 2, 3, 4, 5].iter().cycle() { | |
channel.set_duty(max_duty * numerator / 5)?; | |
Ets.delay_ms(2000)?; | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rust-esp32-std-demo/src/bin/ledc-simple.rs