async-button

Crates.ioasync-button
lib.rsasync-button
version0.1.0
sourcesrc
created_at2023-12-02 21:40:34.966127
updated_at2023-12-02 21:40:34.966127
descriptionAsync button handling crate for no_std environments
homepage
repositoryhttps://github.com/avsaase/async-button
max_upload_size
id1056399
size34,123
Alexander van Saase (avsaase)

documentation

README

Async Button

Async button handling crate for no_std environments. Built around embedded-hal 1.0 traits and embassy-time.

  • Detect button presses without blocking execution of other tasks or unnecessary polling.
  • Debouncing
  • Detect single and multiple short presses
  • Detect long presses
  • Detect sequences of short and long presses or multiple long presses. Open an issue if this would be useful to you, or submit a PR!

Example

let pin = /* Input pin */;
let mut button = Button::new(pin, ButtonConfig::default());

// In a separate task:
loop {
    match button.update().await {
        ButtonEvent::ShortPress { count } => {/* Do something with short presses */},
        ButtonEvent::LongPress => {/* Do something with long press */},
    }
}

Features

  • defmt: derives defmt::Format on public types (except Button).
  • std: uses tokio instead of embassy-time. Mainly useful for tests.

License

Licensed under either of

at your option.

Commit count: 20

cargo fmt