From 635dfd9467aeda0d06f4dd393638db69d424ff41 Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Wed, 1 Dec 2021 14:36:19 -0500 Subject: [PATCH] using an external power supply crashes my light strip --- src/main.rs | 18 ++++++++++-------- src/util/lights.rs | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4a4d885..35b02a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; } } diff --git a/src/util/lights.rs b/src/util/lights.rs index be54459..ac7fd90 100644 --- a/src/util/lights.rs +++ b/src/util/lights.rs @@ -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 = 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() }