Skip to content

Commit

Permalink
examples: raspberry-pi: Add RGB LEDs and multiple PWMs values
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Nov 27, 2024
1 parent a3ac817 commit 292c4a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ sk6812_rpi = "0.1"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
rand = "0.8.5"

[[bench]]
name = "bench"
Expand Down
18 changes: 16 additions & 2 deletions examples/raspberry-pi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use navigator_rs::Navigator;
use std::thread::sleep;
use std::time::Duration;

use rand::seq::SliceRandom;

fn main() {
println!("Creating your navigator module!");
let mut nav = Navigator::new();
Expand All @@ -10,8 +12,20 @@ fn main() {
nav.set_pwm_enable(true);
nav.set_pwm_frequency(60.0);

let colors = [
[255u8, 0, 0],
[0, 255, 0],
[0, 0, 255],
[255, 255, 0],
[0, 255, 255],
[255, 0, 255],
];

loop {
nav.set_duty_cycle_all(0.25);
sleep(Duration::from_millis(1000));
for value in [0.25, 0.5, 0.75, 0.5] {
nav.set_neopixel(&[*colors.choose(&mut rand::thread_rng()).unwrap()]);
nav.set_duty_cycle_all(value);
sleep(Duration::from_millis(1000));
}
}
}

0 comments on commit 292c4a3

Please sign in to comment.