#![no_std] #![no_main] 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::*; use panic_halt as _; #[entry] fn main() -> ! { let p = Peripherals::take(); 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 = 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 [ [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, 1], [0, 0, 1], [1, 0, 1], ] .iter() .cycle() { let _ = r.set_duty(*r_state); let _ = g.set_duty(*g_state); let _ = b.set_duty(*b_state); delay.delay_millis(200u32); } loop {} }