leds/src/main.rs

40 lines
965 B
Rust

pub mod util;
use util::lights::*;
use std::sync::{Arc, RwLock};
use std::thread;
use rs_ws281x::{RawColor, Controller, ControllerBuilder, ChannelBuilder, StripType};
pub const LED_SIZE: i32 = 450;
pub const BRIGHTNESS: u8 = 255;
fn main() {
let p: RawColor = [0, 0, 0, 0];
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
let lock_c = Arc::clone(&lock);
let controller = ControllerBuilder::new()
.channel(ChannelBuilder::new()
.pin(18)
.count(LED_SIZE)
.strip_type(StripType::Ws2812)
.brightness(BRIGHTNESS)
.build()
)
.build();
thread::spawn(move || loop {
let lights = lock_c.read().unwrap();
run_lights(&controller, &lights);
});
let mut x: u8 = 0;
loop {
if x == 255 {
x = 0;
}
let color: RawColor = [x, x, x, 255];
let mut lights = lock.write().unwrap();
lights[0] = color;
x += 1;
}
}