Open weiying-chen opened 3 months ago
I also tried this:
use anyhow::Result;
use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_svc::log::EspLogger;
use esp_idf_sys::{self as _};
use log::info;
use smart_leds_trait::{SmartLedsWrite, RGB8};
use ws2812_esp32_rmt_driver::Ws2812Esp32Rmt;
fn main() -> Result<()> {
esp_idf_svc::sys::link_patches();
EspLogger::initialize_default();
let peripherals = Peripherals::take()?;
let led_pin = peripherals.pins.gpio10; // Assuming GPIO10 is used for the LED data pin
println!("Initializing WS2812 LED strip");
let channel = peripherals.rmt.channel0;
let mut ws2812 = Ws2812Esp32Rmt::new(channel, led_pin).unwrap();
// Define an array of LED colors
let mut leds = vec![RGB8 { r: 0, g: 0, b: 0 }; 8]; // 8 LEDs initialized to off
loop {
info!("Turn ON");
// Set the color of all LEDs to red
for led in leds.iter_mut() {
*led = RGB8 { r: 255, g: 0, b: 0 };
}
ws2812.write(leds.iter().cloned()).unwrap();
// Add a delay to keep the color on for a while
FreeRtos::delay_ms(1000);
info!("Turn OFF");
// Turn off all LEDs
for led in leds.iter_mut() {
*led = RGB8 { r: 0, g: 0, b: 0 };
}
ws2812.write(leds.iter().cloned()).unwrap();
// Add a delay before the next loop iteration
FreeRtos::delay_ms(1000);
}
}
Same: No errors. But the LED doesn't turn on.
W (335) rmt(legacy): legacy driver is deprecated, please migrate to `driver/rmt_tx.h` and/or `driver/rmt_rx.h`
W (345) timer_group: legacy driver is deprecated, please migrate to `driver/gptimer.h`
I (354) sleep: Configure to isolate all GPIO pins in sleep state
I (361) sleep: Enable automatic switching of GPIO sleep configuration
I (368) app_start: Starting scheduler on CPU0
I (373) main_task: Started on CPU0
I (373) main_task: Calling app_main()
Initializing WS2812 LED strip
I (383) heavy_cloud: Turn ON
I (1383) heavy_cloud: Turn OFF
Ah, I found out it works with an external WS2812. So it doesn't work with the built-in WS2812 of the ESP32-C3-Zero for some reason.
I tried the crate like this with my ESP32-C3-Zero:
The code compiles, but the LED is not turning on.
Note this is my cargo file: