pub struct Debounce { /* private fields */ }Expand description
Cleans a noisy boolean signal by requiring it to hold steady before reporting a change.
A mechanical switch, a relay contact, or a reading crossing a threshold does not flip
cleanly: for a few milliseconds it chatters between states. A Debounce reports a
change only after the new value has been seen for a set number of consecutive samples,
so a button press, a float-switch trip, or a threshold crossing reads as one clean
event. This is the standard counter debounce: N stable samples accept a change, and any
contrary sample resets the count. At a fixed sample rate, N samples is the debounce time
- sampling every 5 ms with
samplesof4debounces over 20 ms.
§Examples
use pamoja_kit::Debounce;
// A button needs three stable samples to register.
let mut button = Debounce::new(3, false);
assert!(!button.update(true)); // first press sample
assert!(!button.update(false)); // the contact bounced back
assert!(!button.update(true)); // counting restarts
assert!(!button.update(true));
assert!(button.update(true)); // three in a row: pressedImplementations§
Trait Implementations§
impl Copy for Debounce
impl Eq for Debounce
impl StructuralPartialEq for Debounce
Auto Trait Implementations§
impl Freeze for Debounce
impl RefUnwindSafe for Debounce
impl Send for Debounce
impl Sync for Debounce
impl Unpin for Debounce
impl UnsafeUnpin for Debounce
impl UnwindSafe for Debounce
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more