Debounce a mechanical switch by periodic sampling.
Dependents: RedButton WS_7_Seg_mit_LM1635 WS_7_Seg_mit_LM1635 Lichtschalter_M0 ... more
Diff: Debouncer.h
- Revision:
- 2:7f2f00805d41
- Parent:
- 0:2359961af424
--- a/Debouncer.h Mon May 18 13:08:33 2015 +0000 +++ b/Debouncer.h Mon May 18 13:25:07 2015 +0000 @@ -29,14 +29,14 @@ private: FunctionPointer fun_fall, fun_rise; DigitalIn in; + uint32_t previous; + uint8_t _samples; bool now; - int _samples; - uint32_t previous; void tick(void); public: Debouncer(PinName pin, PinMode mode = PullUp); - Debouncer &samples(int n = 8); + Debouncer &samples(uint8_t n = 8); Debouncer &period(float seconds = 3.90625e-3); operator bool(void);