2021-12-23 19:34:26 +00:00
|
|
|
pub mod util;
|
|
|
|
|
|
|
|
use util::lights::*;
|
2021-12-24 16:39:02 +00:00
|
|
|
use std::sync::{Arc, RwLock};
|
2021-12-24 23:54:53 +00:00
|
|
|
use rs_ws281x::{RawColor, Controller, ControllerBuilder, ChannelBuilder, StripType};
|
2021-12-01 19:36:19 +00:00
|
|
|
use std::{thread, time};
|
2021-12-23 19:34:26 +00:00
|
|
|
|
2021-12-01 19:36:19 +00:00
|
|
|
pub const LED_SIZE: usize = 450; //450
|
|
|
|
pub const BRIGHTNESS: u8 = 150;
|
2021-12-23 19:34:26 +00:00
|
|
|
|
|
|
|
fn main() {
|
2021-12-24 18:29:57 +00:00
|
|
|
let p: RawColor = [0, 0, 0, 0];
|
2021-12-24 16:39:02 +00:00
|
|
|
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
|
|
|
|
let lock_c = Arc::clone(&lock);
|
2021-12-24 23:54:53 +00:00
|
|
|
|
2021-12-01 01:27:28 +00:00
|
|
|
thread::spawn(move || {
|
|
|
|
let mut controller: Controller = ControllerBuilder::new()
|
|
|
|
.channel(0, ChannelBuilder::new()
|
2021-12-24 23:54:53 +00:00
|
|
|
.pin(18)
|
2021-12-01 01:27:28 +00:00
|
|
|
.count(i32::try_from(LED_SIZE).unwrap())
|
2021-12-24 23:54:53 +00:00
|
|
|
.strip_type(StripType::Ws2812)
|
|
|
|
.brightness(BRIGHTNESS)
|
|
|
|
.build()
|
|
|
|
)
|
2021-12-01 00:55:08 +00:00
|
|
|
.build()
|
|
|
|
.expect("Could not construct LED Controller.");
|
2021-12-01 01:27:28 +00:00
|
|
|
loop {
|
2021-12-01 00:55:08 +00:00
|
|
|
let lights = lock_c.read().expect("Could not read array lock.");
|
2021-12-01 19:36:19 +00:00
|
|
|
run_lights(&mut controller, &lights).expect("Error running lights controller.");
|
2021-12-01 01:27:28 +00:00
|
|
|
}
|
2021-12-23 19:34:26 +00:00
|
|
|
});
|
|
|
|
let mut x: u8 = 0;
|
2021-12-01 19:36:19 +00:00
|
|
|
loop {
|
|
|
|
thread::sleep(time::Duration::from_millis(250));
|
2021-12-23 19:34:26 +00:00
|
|
|
if x == 255 {
|
|
|
|
x = 0;
|
|
|
|
}
|
2021-12-01 19:36:19 +00:00
|
|
|
let mut color: RawColor = [x, x, x, 150];
|
2021-12-23 19:34:26 +00:00
|
|
|
let mut lights = lock.write().unwrap();
|
2021-12-01 19:36:19 +00:00
|
|
|
for i in 0..LED_SIZE {
|
|
|
|
lights[i] = color;
|
|
|
|
}
|
2021-12-23 19:34:26 +00:00
|
|
|
x += 1;
|
|
|
|
}
|
|
|
|
}
|