Skip to content

Commit

Permalink
feat: managing the LED panel
Browse files Browse the repository at this point in the history
  • Loading branch information
DavSanchez committed Jun 12, 2024
1 parent 81b2e97 commit 3be2683
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ smoltcp = { version = "0.11.0", default-features = false, features = [
"socket-udp",
] }
esp-hal-smartled = { version = "0.11.0", features = ["esp32s3"] }
smart-leds = "0.4.0"

[profile.dev]
# Rust debug is too slow.
Expand Down
48 changes: 30 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
gpio::{Io, Level, Output},
peripherals::Peripherals,
prelude::*,
rmt::Rmt,
clock::ClockControl, delay::Delay, gpio::Io, peripherals::Peripherals, prelude::*, rmt::Rmt,
system::SystemControl,
};
use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter};
use smart_leds::{
brightness, gamma,
hsv::{hsv2rgb, Hsv},
SmartLedsWrite,
};

#[entry]
fn main() -> ! {
Expand All @@ -29,22 +29,34 @@ fn main() -> ! {
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks, None).unwrap();
let rmt_buffer = smartLedBuffer!(1);
let rmt_buffer = smartLedBuffer!(36);
let mut a_led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio5, rmt_buffer, &clocks);

let mut led_red = Output::new(io.pins.gpio8, Level::High);
let mut led_blue = Output::new(io.pins.gpio9, Level::Low);

let delay = Delay::new(&clocks);

// Color management
let mut color = Hsv {
hue: 0,
sat: 255,
val: 255,
};
let mut data;

loop {
led_red.toggle();
led_blue.toggle();
delay.delay_millis(500);
led_red.toggle();
led_blue.toggle();

// or using `fugit` duration
delay.delay(2.secs());
// Iterate over the rainbow!
for hue in 0..=255 {
color.hue = hue;
// Convert from the HSV color space (where we can easily transition from one
// color to the other) to the RGB color space that we can then send to the LED
data = [hsv2rgb(color); 36];
// When sending to the LED, we do a gamma correction first (see smart_leds
// documentation for details) and then limit the brightness to 10 out of 255 so
// that the output it's not too bright.
a_led
.write(brightness(gamma(data.iter().cloned()), 15))
.unwrap();

delay.delay_millis(15);
}
}
}

0 comments on commit 3be2683

Please sign in to comment.