Expand description
Simple abstraction of a button attached to a GPIO port.
§Usage
Create the button using one of the constructors provided by the avr_oxide::devices::UsesPin
trait.
The AVR’s internal pullup can be enabled/disabled using the
pullup
method.
State can be queried using the is_pressed
or state
methods, or
alternatively a closure can be provided as a callback to be called
whenever the button’s state changes using the on_click
method.
#[avr_oxide::main(chip="atmega4809")]
pub fn main() {
let supervisor = avr_oxide::oxide::instance();
let mut green_button = StaticWrap::new(OxideButton::using(Debouncer::with_pin(board::pin_a(2))));
green_button.borrow().on_click(Box::new(move |_pinid, state|{
match state {
ButtonState::Released => {
// Do something
}
ButtonState::Pressed => {
// Do something
}
ButtonState::Unknown => {
// Probably don't do anything
}
}
}));
// Tell the supervisor which devices to listen to
supervisor.listen(green_button.borrow());
// Now enter the event loop
supervisor.run();
}
Structs§
- Encapsulation of a Button attached to a standard GPIO pin. Generates Oxide events on button events (press/release.)
Enums§
- Button states passed in Oxide events.