Trait switch_hal::InputSwitch

source ·
pub trait InputSwitch {
    type Error;

    // Required method
    fn is_active(&self) -> Result<bool, Self::Error>;
}
Expand description

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

Required Associated Types§

Required Methods§

source

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::{InputSwitch, OutputSwitch, Switch, IntoSwitch};
let button = pin.into_active_low_switch();
match button.is_active() {
    Ok(true) => { status_led.on().ok(); }
    Ok(false) => { status_led.off().ok(); }
    Err(_) => { panic!("Failed to read button state"); }
}

Implementors§