feat: 实现流光效果。

This commit is contained in:
2022-08-06 09:15:09 +08:00
commit f96c825034
7 changed files with 127 additions and 0 deletions

36
src/main.rs Normal file
View File

@@ -0,0 +1,36 @@
#![feature(is_some_with)]
#![feature(core_intrinsics)]
use smart_leds::hsv::{hsv2rgb, Hsv};
use smart_leds::SmartLedsWrite;
use std::thread::sleep;
use std::{env,time::Duration};
use ws2812_esp32_rmt_driver::Ws2812Esp32Rmt;
use esp_idf_sys::*;
fn main() {
env::set_var("DEFMT_LOG", "trace");
env::set_var("RUST_LOG", "trace");
// env_logger::init();
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
// or else some patches to the runtime implemented by esp-idf-sys might not link properly.
esp_idf_sys::link_patches();
let mut ws2812 = Ws2812Esp32Rmt::new(0, 1).unwrap();
println!("Start NeoPixel rainbow!");
let mut hue = unsafe { esp_random() } as u8;
loop {
let pixels = (0..60).map(|i: u8| {
let hue = hue.wrapping_add(i.wrapping_mul(4));
let sat = 170;
let val = 250;
let rgb = hsv2rgb(Hsv { hue, sat, val });
rgb
});
ws2812.write(pixels).unwrap();
sleep(Duration::from_millis(20));
hue = hue.wrapping_add(1);
}
}