// pwm_blinkled.rs - Blinks an LED using hardware PWM. // // Remember to add a resistor of an appropriate value in series, to prevent // exceeding the maximum current rating of the GPIO pin and the LED. // // Interrupting the process by pressing Ctrl-C causes the application to exit // immediately without disabling the PWM channel. Check out the // gpio_blinkled_signals.rs example to learn how to properly handle incoming // signals to prevent an abnormal termination. use std::error::Error; use std::thread; use std::time::Duration; use rppal::pwm::{Channel, Polarity, Pwm}; fn main() -> Result<(), Box> { // Enable PWM channel 0 (BCM GPIO 18, physical pin 12) at 2 Hz with a 25% duty cycle. let pwm = Pwm::with_frequency(Channel::Pwm0, 2.0, 0.25, Polarity::Normal, true)?; // Sleep for 2 seconds while the LED blinks. thread::sleep(Duration::from_secs(2)); // Reconfigure the PWM channel for an 8 Hz frequency, 50% duty cycle. pwm.set_frequency(8.0, 0.5)?; thread::sleep(Duration::from_secs(3)); Ok(()) // When the pwm variable goes out of scope, the PWM channel is automatically disabled. // You can manually disable the channel by calling the Pwm::disable() method. }