[][src]Module rmicrobit::buttons::core

Low-level button drivers.

This module provides an interface for reading a button's state, and an implementation of that interface for a GPIO pin.

Use this module's PollButton interface rather than the monitors if you need to react to both presses and releases.

Use this module's Button to access an externally-connected button or switch, or to specify a debouncing algorithm.

Examples

This example is not tested
use rmicrobit::prelude::*;
use rmicrobit::gpio::PinsByKind;
use rmicrobit::buttons;
use rmicrobit::buttons::core::TransitionEvent;
use rmicrobit::buttons::builtin::{ButtonA, ButtonB};
let p: nrf51::Peripherals = _;
let PinsByKind {button_pins, ..} = p.GPIO.split_by_kind();
let (button_a, button_b) = buttons::from_pins(button_pins);
loop {
    // every 6ms
    match button_a.poll_event() {
        Some(TransitionEvent::Press) => {}
        Some(TransitionEvent::Release) => {}
        None => {}
    }
    match button_b.poll_event() {
        ...
    }
}

See examples/use_core_buttons.rs for a complete example.

Structs

Button

A button based on a GPIO pin.

Transition

Old and new button states.

Enums

TransitionEvent

A press or release event.

Traits

PollButton

A button which can be polled.