pub struct Led { /* private fields */ }Expand description
Represents a LED controlled by a digital pin. There are two kinds of pins that can be used:
- OUTPUT: for digital on/off led
- PWM: for more control on the LED brightness
Implementations§
Source§impl Led
impl Led
Sourcepub fn new(board: &dyn Hardware, pin: u8, default: bool) -> Result<Self, Error>
pub fn new(board: &dyn Hardware, pin: u8, default: bool) -> Result<Self, Error>
Creates an instance of a LED attached to a given board.
§Errors
UnknownPin: this function will bail an error if the pin does not exist for this board.IncompatibleMode: this function will bail an error if the pin does not support OUTPUT or PWM mode.
Sourcepub fn toggle(&mut self) -> Result<&Self, Error>
pub fn toggle(&mut self) -> Result<&Self, Error>
Toggles the current state, if on then turn off, if off then turn on.
Sourcepub fn blink(&mut self, ms: u64) -> &Self
pub fn blink(&mut self, ms: u64) -> &Self
Blinks the LED on/off in phases of milliseconds duration.
This is an animation and can be stopped by calling Led::stop().
Sourcepub fn pulse(&mut self, ms: u64) -> &Self
pub fn pulse(&mut self, ms: u64) -> &Self
Pulses the LED on/off (using fading) in phases of ms (milliseconds) duration.
This is an animation and can be stopped by calling Led::stop().
Sourcepub fn get_brightness(&self) -> u8
pub fn get_brightness(&self) -> u8
Returns the LED current brightness in percentage (0-100%).
Sourcepub fn set_brightness(self, brightness: u8) -> Result<Self, Error>
pub fn set_brightness(self, brightness: u8) -> Result<Self, Error>
Set the LED brightness (integer between 0-100) in percent of the max brightness. If a number higher than 100 is used, the brightness is set to 100%. If the requested brightness is 100%, the LED will reset to simple on/off (OUTPUT) mode.
§Errors
IncompatiblePin: this function will bail an error if the LED pin does not support PWM.
Trait Implementations§
Source§impl Output for Led
impl Output for Led
Source§fn set_state(&mut self, state: State) -> Result<State, Error>
fn set_state(&mut self, state: State) -> Result<State, Error>
Internal only: you should rather use Self::turn_on(), Self::turn_off(), Self::set_brightness() functions.