[][src]Trait switch_hal::InputSwitch

pub trait InputSwitch {
    type Error;
    fn is_active(&self) -> Result<bool, Self::Error>;
}

Represents an input switch, such as a button or a switch

Associated Types

type Error

Loading content...

Required methods

fn is_active(&self) -> Result<bool, Self::Error>

Returns true if the swich has been activated, otherwise false i.e. if a button is currently pressed, returns true

Examples

use switch_hal::{ActiveLow, InputSwitch, OutputSwitch, Switch};
let button = Switch::<_, ActiveLow>::new(pin);
match button.is_active() {
    Ok(true) => { status_led.on().ok(); }
    Ok(false) => { status_led.off().ok(); }
    Err(_) => { panic!("Failed to read button state"); }
}
Loading content...

Implementors

impl<T: InputPin> InputSwitch for Switch<T, ActiveHigh>[src]

type Error = <T as InputPin>::Error

impl<T: InputPin> InputSwitch for Switch<T, ActiveLow>[src]

type Error = <T as InputPin>::Error

Loading content...