test LED has now ledc initialized
This commit is contained in:
@@ -104,7 +104,6 @@ async fn main(spawner: Spawner) -> ! {
|
||||
mqtt_publish("esp32/topic", b"hello from ESP32 (init)", QualityOfService::QoS1, false).await;
|
||||
info!("Sent initial MQTT message");
|
||||
|
||||
// Subscribe to your topics (can be done anytime; command is queued)
|
||||
mqtt_subscribe("esp32/topic").await;
|
||||
|
||||
// Get a receiver for incoming MQTT messages
|
||||
|
||||
@@ -35,7 +35,7 @@ static TCP_TX_BUFFER: ConstStaticCell<[u8; 2048]> = ConstStaticCell::new([0; 204
|
||||
static MQTT_TX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
||||
static MQTT_RX_BUF: ConstStaticCell<[u8; 1024]> = ConstStaticCell::new([0; 1024]);
|
||||
|
||||
// Tie TcpSocket lifetime to session, MQTT buffers to 'a (fixes E0521).
|
||||
// Tie TcpSocket lifetime to session
|
||||
type Client<'a, 'net> = MqttClient<'a, TcpSocket<'net>, 8, CountingRng>;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
||||
@@ -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