test LED has now ledc initialized
This commit is contained in:
@@ -37,8 +37,49 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
info!("Embassy initialized!");
|
||||
|
||||
|
||||
// LEDC initialization
|
||||
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),
|
||||
clock_source: timer::LSClockSource::APBClk,
|
||||
})
|
||||
.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,
|
||||
pin_config: channel::config::PinConfig::PushPull,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
info!("LEDC configured successfully");
|
||||
let mut brightness: i32 = 0;
|
||||
let mut direction: i32 = 5;
|
||||
|
||||
loop {
|
||||
Timer::after(Duration::from_millis(50)).await;
|
||||
// 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;
|
||||
}
|
||||
|
||||
Timer::after(Duration::from_millis(30)).await;
|
||||
}
|
||||
|
||||
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
||||
|
||||
Reference in New Issue
Block a user