led on gpio2 working
This commit is contained in:
@@ -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::<LowSpeed>(timer::Number::Timer0);
|
||||
pwm_timer
|
||||
.configure(timer::config::Config {
|
||||
duty: timer::config::Duty::Duty14Bit,
|
||||
frequency: Rate::from_hz(1000),
|
||||
let mut lstimer0 = ledc.timer::<LowSpeed>(timer::Number::Timer0);
|
||||
lstimer0.configure(timer::config::Config {
|
||||
duty: timer::config::Duty::Duty5Bit,
|
||||
clock_source: timer::LSClockSource::APBClk,
|
||||
})
|
||||
.unwrap();
|
||||
frequency: Rate::from_khz(24),
|
||||
}).unwrap();
|
||||
|
||||
let mut pwm_channel =
|
||||
ledc.channel::<LowSpeed>(channel::Number::Channel0, peripherals.GPIO1);
|
||||
|
||||
pwm_channel
|
||||
.configure(channel::config::Config {
|
||||
timer: &pwm_timer,
|
||||
duty_pct: 0,
|
||||
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();
|
||||
|
||||
info!("LEDC configured successfully");
|
||||
let mut brightness: i32 = 0;
|
||||
let mut direction: i32 = 5;
|
||||
}).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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user