Expand description
A platform-agnostic debounce library.
This library provides an update() method to debounce a pin.
Implements approach 1 from here (archived 2018-09-03).
It also adds a wrapper for an InputPin that debounces it’s
is_high() and is_low() methods.
§Implementation
The InputPin wrapper checks only the debounced state.
It does not poll the pin and drives the debouncing poll implementation forward.
To do this, you have to call update(). At best call it every 1ms in an ISR.
§Example
For examples check the examples directory in the repository.
ⓘ
use debounced_pin::prelude::*;
use debounced_pin::ActiveHigh;
// This is up to the implementation details of the embedded_hal you are using.
let pin: InputPin = hal_function_which_returns_input_pin();
let pin = DebouncedInputPin::new(pin, ActiveHigh);
loop {
match pin.update()? {
// Pin is not active.
DebounceState::NotActive => break,
// Pin was reset or is not active in general.
DebounceState::Reset => break,
// Pin is active but still debouncing.
DebounceState::Debouncing => continue,
// Pin is active and debounced.
DebounceState::Active => break,
}
// Wait to poll again in 1ms. Also hardware specific.
wait(1.ms());
}
// If the debounce state is DebounceState::Active
// this returns true and the code gets executed,
// else this false.
if pin.is_high()? {
// Do something with it
break;
}Modules§
- prelude
- Import the needed types and traits to use the
update()method.
Structs§
- Active
High - Unit struct for active-high pins.
- Active
Low - Unit struct for active-low pins.
- Debounced
Input Pin - A debounced input pin.
Enums§
- Debounce
State - The debounce state of the
update()method.
Traits§
- Debounce
- Debounce Trait which provides an
update()method which debounces the pin.