Struct Button

Source
pub struct Button { /* private fields */ }
Expand description

Represents a simple push button or switch. Connect one side of the button to a ground pin, and the other to any GPIO pin. The GPIO pin will be pulled high by default. Alternatively, connect one side of the button to the 3V3 pin, and the other to any GPIO pin, and then create a Button instance with Button::new_with_pulldown

Implementations§

Source§

impl Button

Source

pub fn new(pin: u8) -> Button

Returns a Button with the pin number given and the pin pulled high with an internal resistor by default

  • pin - The GPIO pin which the device is attached to
Examples found in repository?
examples/button.rs (line 7)
5fn main() {
6    // Create a button which is attached to Pin 17
7    let mut button = Button::new(17);
8    button.wait_for_press(None);
9    println!("button pressed");
10}
Source

pub fn new_with_pulldown(pin: u8) -> Button

Returns a Button with the pin number given and the pin pulled down with an internal resistor by default

  • pin - The GPIO pin which the device is attached to
Source

pub fn is_active(&self) -> bool

Returns True if the device is currently active and False otherwise.

Source

pub fn close(self)

Shut down the device and release all associated resources.

Source

pub fn pin(&self) -> u8

The Pin that the device is connected to.

Source

pub fn value(&self) -> bool

Returns True if the device is currently active and False otherwise.

Source

pub fn wait_for_release(&mut self, timeout: Option<f32>)

  • timeout - Number of seconds to wait before proceeding. If this is None, then wait indefinitely until the device is inactive.
Source

pub fn wait_for_press(&mut self, timeout: Option<f32>)

Pause the program until the device is activated, or the timeout is reached.

  • timeout - Number of seconds to wait before proceeding. If this is None, then wait indefinitely until the device is active.
Examples found in repository?
examples/button.rs (line 8)
5fn main() {
6    // Create a button which is attached to Pin 17
7    let mut button = Button::new(17);
8    button.wait_for_press(None);
9    println!("button pressed");
10}

Auto Trait Implementations§

§

impl Freeze for Button

§

impl !RefUnwindSafe for Button

§

impl Send for Button

§

impl Sync for Button

§

impl Unpin for Button

§

impl !UnwindSafe for Button

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.