using an external power supply crashes my light strip
This commit is contained in:
parent
a172e0afee
commit
635dfd9467
2 changed files with 13 additions and 11 deletions
16
src/main.rs
16
src/main.rs
|
@ -2,11 +2,11 @@ pub mod util;
|
||||||
|
|
||||||
use util::lights::*;
|
use util::lights::*;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::thread;
|
|
||||||
use rs_ws281x::{RawColor, Controller, ControllerBuilder, ChannelBuilder, StripType};
|
use rs_ws281x::{RawColor, Controller, ControllerBuilder, ChannelBuilder, StripType};
|
||||||
|
use std::{thread, time};
|
||||||
|
|
||||||
pub const LED_SIZE: usize = 450;
|
pub const LED_SIZE: usize = 450; //450
|
||||||
pub const BRIGHTNESS: u8 = 255;
|
pub const BRIGHTNESS: u8 = 150;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let p: RawColor = [0, 0, 0, 0];
|
let p: RawColor = [0, 0, 0, 0];
|
||||||
|
@ -21,23 +21,25 @@ fn main() {
|
||||||
.strip_type(StripType::Ws2812)
|
.strip_type(StripType::Ws2812)
|
||||||
.brightness(BRIGHTNESS)
|
.brightness(BRIGHTNESS)
|
||||||
.build()
|
.build()
|
||||||
.expect("Could not construct LED Channel.");
|
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
.expect("Could not construct LED Controller.");
|
.expect("Could not construct LED Controller.");
|
||||||
loop {
|
loop {
|
||||||
let lights = lock_c.read().expect("Could not read array lock.");
|
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;
|
let mut x: u8 = 0;
|
||||||
loop {
|
loop {
|
||||||
|
thread::sleep(time::Duration::from_millis(250));
|
||||||
if x == 255 {
|
if x == 255 {
|
||||||
x = 0;
|
x = 0;
|
||||||
}
|
}
|
||||||
let color: RawColor = [x, x, x, 255];
|
let mut color: RawColor = [x, x, x, 150];
|
||||||
let mut lights = lock.write().unwrap();
|
let mut lights = lock.write().unwrap();
|
||||||
lights[0] = color;
|
for i in 0..LED_SIZE {
|
||||||
|
lights[i] = color;
|
||||||
|
}
|
||||||
x += 1;
|
x += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@ use rs_ws281x::WS2811Error;
|
||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
pub fn run_lights(controller: &mut Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> {
|
pub fn run_lights(controller: &mut Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> {
|
||||||
// println!("Value: {:?}", strip[0]);
|
println!("Value: {:?}", values[0]);
|
||||||
thread::sleep(time::Duration::from_secs(1));
|
//thread::sleep(time::Duration::from_millis(10));
|
||||||
let channels: Vec<usize> = controller.channels();
|
let channels: Vec<usize> = controller.channels();
|
||||||
let mut strip = controller.leds_mut(channels[0]);
|
let mut strip = controller.leds_mut(channels[0]);
|
||||||
for i in 0..strip.len() {
|
for i in 0..strip.len() {
|
||||||
strip[i] = values[i];
|
strip[i] = values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.render();
|
controller.render().expect("Error rendering.");
|
||||||
controller.wait()
|
controller.wait()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue