-
Help Needed with LEDC Breathing Light on ESP32-C3 I hope this message finds you well. I am encountering an issue while attempting to create a breathing light effect on my ESP32-C3 development board using the LEDC peripheral. The on-board LED is connected to GPIO12, and I’ve been trying to implement the effect using the LEDC module. However, I am facing several challenges that I hope you can help me with. The Problem
This error indicates that peripherals.LEDC has been moved and cannot be borrowed later. My Code
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is your code changed to work (note I also used a different GPIO (3 instead of 12 in your code) #![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
gpio::Io, ledc::{self, timer, LSGlobalClkSource, LowSpeed}, prelude::*
};
#[entry]
fn main() -> ! {
#[allow(unused)]
let peripherals = esp_hal::init(esp_hal::Config::default());
esp_println::logger::init_logger_from_env();
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut ledc_1 = ledc::Ledc::new(peripherals.LEDC);
ledc_1.set_global_slow_clock(LSGlobalClkSource::APBClk);
// you shouldn't try to construct a new timer via `new` but get it from the driver
let mut ledc_timer1 = ledc_1.get_timer::<LowSpeed>(timer::Number::Timer1);
ledc_timer1.configure(ledc::timer::config::Config{
duty: timer::config::Duty::Duty5Bit, // 1 bit won't work here
clock_source: timer::LSClockSource::APBClk,
frequency: 24.kHz(), // 50.kHz() won't work for the duration you want
}).unwrap();
let mut ledc_channel1 = ledc::channel::Channel::<LowSpeed, _>::new(ledc::channel::Number::Channel1, io.pins.gpio3);
ledc_channel1.configure(ledc::channel::config::Config {
timer: &ledc_timer1,
duty_pct: 10,
pin_config: ledc::channel::config::PinConfig::PushPull
}).unwrap();
loop {
ledc_channel1.start_duty_fade(0, 100, 1000).unwrap();
while ledc_channel1.is_duty_fade_running() {}
ledc_channel1.start_duty_fade(100, 0, 1000).unwrap();
while ledc_channel1.is_duty_fade_running() {}
}
} |
Beta Was this translation helpful? Give feedback.
This is your code changed to work (note I also used a different GPIO (3 instead of 12 in your code)