Compare commits
1 commit
cc18fdd3b4
...
8ae02e70a3
Author | SHA1 | Date | |
---|---|---|---|
8ae02e70a3 |
2 changed files with 24 additions and 3 deletions
13
src/main.rs
13
src/main.rs
|
@ -3,14 +3,25 @@ pub mod util;
|
||||||
use util::lights::*;
|
use util::lights::*;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use rs_ws281x::RawColor;
|
use rs_ws281x::{RawColor, Controller, ControllerBuilder, ChannelBuilder, StripType};
|
||||||
|
|
||||||
pub const LED_SIZE: usize = 450;
|
pub const LED_SIZE: usize = 450;
|
||||||
|
pub const BRIGHTNESS: u8 = 255;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let p: RawColor = [0, 0, 0, 0];
|
let p: RawColor = [0, 0, 0, 0];
|
||||||
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
|
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
|
||||||
let lock_c = Arc::clone(&lock);
|
let lock_c = Arc::clone(&lock);
|
||||||
|
|
||||||
|
let controller: Controller = ControllerBuilder::new()
|
||||||
|
.channel(ChannelBuilder::new()
|
||||||
|
.pin(18)
|
||||||
|
.count(LED_SIZE)
|
||||||
|
.strip_type(StripType::Ws2812)
|
||||||
|
.brightness(BRIGHTNESS)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build();
|
||||||
thread::spawn(move || loop {
|
thread::spawn(move || loop {
|
||||||
let lights = lock_c.read().unwrap();
|
let lights = lock_c.read().unwrap();
|
||||||
run_lights(&lights);
|
run_lights(&lights);
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
use rs_ws281x::RawColor;
|
use rs_ws281x::RawColor;
|
||||||
|
use rs_ws281x::Controller;
|
||||||
|
use rs_ws281x::WS2811Error;
|
||||||
|
|
||||||
pub fn run_lights(strip: &[RawColor; crate::LED_SIZE]) {
|
pub fn run_lights(controller: &Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> {
|
||||||
println!("Value: {:?}", strip[0]);
|
// println!("Value: {:?}", strip[0]);
|
||||||
|
let channels: Vec<usize> = controller.channels();
|
||||||
|
let mut strip = controller.leds_mut(channels[0]);
|
||||||
|
for x in 0..strip.len() {
|
||||||
|
strip[i] = values[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.render();
|
||||||
|
controller.wait()
|
||||||
}
|
}
|
Loading…
Reference in a new issue