feat: dim led to 1% brightness
This commit is contained in:
parent
c6887897a5
commit
fefe476034
65
src/main.rs
65
src/main.rs
|
@ -4,6 +4,7 @@
|
|||
use esp_hal::clock::ClockControl;
|
||||
use esp_hal::delay::Delay;
|
||||
use esp_hal::gpio::IO;
|
||||
use esp_hal::ledc::{channel, timer, LSGlobalClkSource, LEDC};
|
||||
use esp_hal::peripherals::Peripherals;
|
||||
use esp_hal::prelude::*;
|
||||
|
||||
|
@ -15,30 +16,70 @@ fn main() -> ! {
|
|||
let sys = p.SYSTEM.split();
|
||||
let clocks = ClockControl::boot_defaults(sys.clock_control).freeze();
|
||||
|
||||
let mut ledc = LEDC::new(p.LEDC, &clocks);
|
||||
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
|
||||
|
||||
let mut timer = ledc.get_timer(timer::Number::Timer0);
|
||||
timer
|
||||
.configure(timer::config::Config {
|
||||
clock_source: timer::LSClockSource::APBClk,
|
||||
duty: timer::config::Duty::Duty8Bit,
|
||||
frequency: 24.kHz(),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let io = IO::new(p.GPIO, p.IO_MUX);
|
||||
|
||||
let mut r = io.pins.gpio5.into_push_pull_output();
|
||||
let mut g = io.pins.gpio6.into_push_pull_output();
|
||||
let mut b = io.pins.gpio7.into_push_pull_output();
|
||||
let mut r = ledc.get_channel(
|
||||
channel::Number::Channel0,
|
||||
io.pins.gpio5.into_push_pull_output(),
|
||||
);
|
||||
let mut g = ledc.get_channel(
|
||||
channel::Number::Channel1,
|
||||
io.pins.gpio6.into_push_pull_output(),
|
||||
);
|
||||
let mut b = ledc.get_channel(
|
||||
channel::Number::Channel2,
|
||||
io.pins.gpio7.into_push_pull_output(),
|
||||
);
|
||||
|
||||
r.configure(channel::config::Config {
|
||||
duty_pct: 0,
|
||||
pin_config: channel::config::PinConfig::PushPull,
|
||||
timer: &timer,
|
||||
})
|
||||
.unwrap();
|
||||
g.configure(channel::config::Config {
|
||||
duty_pct: 0,
|
||||
pin_config: channel::config::PinConfig::PushPull,
|
||||
timer: &timer,
|
||||
})
|
||||
.unwrap();
|
||||
b.configure(channel::config::Config {
|
||||
duty_pct: 0,
|
||||
pin_config: channel::config::PinConfig::PushPull,
|
||||
timer: &timer,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let _btn = io.pins.gpio9.into_pull_up_input();
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
|
||||
for [r_state, g_state, b_state] in [
|
||||
[true, false, false],
|
||||
[true, true, false],
|
||||
[false, true, false],
|
||||
[false, true, true],
|
||||
[false, false, true],
|
||||
[true, false, true],
|
||||
[1, 0, 0],
|
||||
[1, 1, 0],
|
||||
[0, 1, 0],
|
||||
[0, 1, 1],
|
||||
[0, 0, 1],
|
||||
[1, 0, 1],
|
||||
]
|
||||
.iter()
|
||||
.cycle()
|
||||
{
|
||||
r.set_state(*r_state);
|
||||
g.set_state(*g_state);
|
||||
b.set_state(*b_state);
|
||||
let _ = r.set_duty(*r_state);
|
||||
let _ = g.set_duty(*g_state);
|
||||
let _ = b.set_duty(*b_state);
|
||||
|
||||
delay.delay_millis(200u32);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue