PWMLED

Struct PWMLED 

Source
pub struct PWMLED(/* private fields */);
Expand description

Represents a light emitting diode (LED) with variable brightness. A typical configuration of such a device is to connect a GPIO pin to the anode (long leg) of the LED, and the cathode (short leg) to ground, with an optional resistor to prevent the LED from burning out.

Implementations§

Source§

impl PWMLED

Source

pub fn new(pin: u8) -> PWMLED

Returns a PMWLED with the pin number given

  • pin - The GPIO pin which the device is attached to
Examples found in repository?
examples/softpwm.rs (line 7)
5fn main() {
6    // Create a new LED attached to Pin 17
7    let mut led = PWMLED::new(17);
8
9    // blink the LED 5 times
10    led.set_blink_count(5);
11    led.blink(2.0, 2.0, 1.0, 1.0);
12
13    // wait for key press to exit
14    let _ = io::stdin().read(&mut [0u8]).unwrap();
15}

Make the device turn on and off repeatedly

  • on_time - Number of seconds on
  • off_time - Number of seconds off
  • fade_in_time - Number of seconds to spend fading in
  • fade_out_time - Number of seconds to spend fading out
Examples found in repository?
examples/softpwm.rs (line 11)
5fn main() {
6    // Create a new LED attached to Pin 17
7    let mut led = PWMLED::new(17);
8
9    // blink the LED 5 times
10    led.set_blink_count(5);
11    led.blink(2.0, 2.0, 1.0, 1.0);
12
13    // wait for key press to exit
14    let _ = io::stdin().read(&mut [0u8]).unwrap();
15}
Source

pub fn on(&mut self)

Turns the device on.

Source

pub fn off(&mut self)

Turns the device off.

Source

pub fn pulse(&mut self, fade_in_time: f32, fade_out_time: f32)

Make the device fade in and out repeatedly.

  • fade_in_time - Number of seconds to spend fading in
  • fade_out_time - Number of seconds to spend fading out
Source

pub fn set_value(&mut self, value: f64)

Set the duty cycle of the PWM device. 0.0 is off, 1.0 is fully on. Values in between may be specified for varying levels of power in the device.

Set the number of times to blink the device

  • n - Number of times to blink
Examples found in repository?
examples/softpwm.rs (line 10)
5fn main() {
6    // Create a new LED attached to Pin 17
7    let mut led = PWMLED::new(17);
8
9    // blink the LED 5 times
10    led.set_blink_count(5);
11    led.blink(2.0, 2.0, 1.0, 1.0);
12
13    // wait for key press to exit
14    let _ = io::stdin().read(&mut [0u8]).unwrap();
15}

Auto Trait Implementations§

§

impl Freeze for PWMLED

§

impl !RefUnwindSafe for PWMLED

§

impl Send for PWMLED

§

impl Sync for PWMLED

§

impl Unpin for PWMLED

§

impl !UnwindSafe for PWMLED

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.