From 75f038262b168e07df4c01aa8a9bafebbb19bd68 Mon Sep 17 00:00:00 2001 From: Priec Date: Sun, 12 Oct 2025 14:16:17 +0200 Subject: [PATCH] led on gpio2 working --- test_LED/src/bin/main.rs | 50 ++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/test_LED/src/bin/main.rs b/test_LED/src/bin/main.rs index 49df249..1cf94e7 100644 --- a/test_LED/src/bin/main.rs +++ b/test_LED/src/bin/main.rs @@ -42,42 +42,26 @@ async fn main(spawner: Spawner) { let mut ledc = Ledc::new(peripherals.LEDC); ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); - let mut pwm_timer = ledc.timer::(timer::Number::Timer0); - pwm_timer - .configure(timer::config::Config { - duty: timer::config::Duty::Duty14Bit, - frequency: Rate::from_hz(1000), - clock_source: timer::LSClockSource::APBClk, - }) - .unwrap(); + let mut lstimer0 = ledc.timer::(timer::Number::Timer0); + lstimer0.configure(timer::config::Config { + duty: timer::config::Duty::Duty5Bit, + clock_source: timer::LSClockSource::APBClk, + frequency: Rate::from_khz(24), + }).unwrap(); - let mut pwm_channel = - ledc.channel::(channel::Number::Channel0, peripherals.GPIO1); - - pwm_channel - .configure(channel::config::Config { - timer: &pwm_timer, - duty_pct: 0, - pin_config: channel::config::PinConfig::PushPull, - }) - .unwrap(); - - info!("LEDC configured successfully"); - let mut brightness: i32 = 0; - let mut direction: i32 = 5; + let led = peripherals.GPIO2; + let mut channel0 = ledc.channel(channel::Number::Channel0, led); + channel0.configure(channel::config::Config { + timer: &lstimer0, + duty_pct: 10, + pin_config: channel::config::PinConfig::PushPull, + }).unwrap(); loop { - // Set current brightness level (0–100 %) - pwm_channel.set_duty(brightness as u8).ok(); - - brightness += direction; - if brightness >= 100 { - brightness = 100; - direction = -5; - } else if brightness <= 0 { - brightness = 0; - direction = 5; - } + channel0.start_duty_fade(0, 100, 1000).unwrap(); + while channel0.is_duty_fade_running() {} + channel0.start_duty_fade(100, 0, 1000).unwrap(); + while channel0.is_duty_fade_running() {} Timer::after(Duration::from_millis(30)).await; }