using an external power supply crashes my light strip

This commit is contained in:
jane 2021-12-01 14:36:19 -05:00
parent a172e0afee
commit 635dfd9467
2 changed files with 13 additions and 11 deletions

View file

@ -2,11 +2,11 @@ pub mod util;
use util::lights::*;
use std::sync::{Arc, RwLock};
use std::thread;
use rs_ws281x::{RawColor, Controller, ControllerBuilder, ChannelBuilder, StripType};
use std::{thread, time};
pub const LED_SIZE: usize = 450;
pub const BRIGHTNESS: u8 = 255;
pub const LED_SIZE: usize = 450; //450
pub const BRIGHTNESS: u8 = 150;
fn main() {
let p: RawColor = [0, 0, 0, 0];
@ -21,23 +21,25 @@ fn main() {
.strip_type(StripType::Ws2812)
.brightness(BRIGHTNESS)
.build()
.expect("Could not construct LED Channel.");
)
.build()
.expect("Could not construct LED Controller.");
loop {
let lights = lock_c.read().expect("Could not read array lock.");
run_lights(&mut controller, &lights);
run_lights(&mut controller, &lights).expect("Error running lights controller.");
}
});
let mut x: u8 = 0;
loop {
loop {
thread::sleep(time::Duration::from_millis(250));
if x == 255 {
x = 0;
}
let color: RawColor = [x, x, x, 255];
let mut color: RawColor = [x, x, x, 150];
let mut lights = lock.write().unwrap();
lights[0] = color;
for i in 0..LED_SIZE {
lights[i] = color;
}
x += 1;
}
}

View file

@ -4,14 +4,14 @@ use rs_ws281x::WS2811Error;
use std::{thread, time};
pub fn run_lights(controller: &mut Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> {
// println!("Value: {:?}", strip[0]);
thread::sleep(time::Duration::from_secs(1));
println!("Value: {:?}", values[0]);
//thread::sleep(time::Duration::from_millis(10));
let channels: Vec<usize> = controller.channels();
let mut strip = controller.leds_mut(channels[0]);
for i in 0..strip.len() {
strip[i] = values[i];
}
controller.render();
controller.render().expect("Error rendering.");
controller.wait()
}