#button #embassy #async #no-std

no-std async-button

Async button handling crate for no_std environments

2 unstable releases

new 0.2.0 Jan 24, 2025
0.1.0 Dec 2, 2023

#683 in Embedded development

Download history 1/week @ 2024-10-05 8/week @ 2024-10-12 2/week @ 2024-10-19 2/week @ 2024-11-02 1/week @ 2024-11-16

83 downloads per month

MIT/Apache

18KB
335 lines

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.

Dependencies

~1–7MB
~42K SLoC