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
impl Button
Sourcepub fn new(pin: u8) -> Button
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
Sourcepub fn new_with_pulldown(pin: u8) -> Button
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
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns True
if the device is currently active and False
otherwise.
Sourcepub fn value(&self) -> bool
pub fn value(&self) -> bool
Returns True
if the device is currently active and False
otherwise.
Sourcepub fn wait_for_release(&mut self, timeout: Option<f32>)
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.
Sourcepub fn wait_for_press(&mut self, timeout: Option<f32>)
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more