Debounce a mechanical switch by periodic sampling.

Dependents:   RedButton WS_7_Seg_mit_LM1635 WS_7_Seg_mit_LM1635 Lichtschalter_M0 ... more

Revision:
2:7f2f00805d41
Parent:
1:e59480cf6c72
--- a/Debouncer.cpp	Mon May 18 13:08:33 2015 +0000
+++ b/Debouncer.cpp	Mon May 18 13:25:07 2015 +0000
@@ -68,14 +68,14 @@
 //! \param pin Pin to poll.
 //! \param mode Pin mode, e.g. \a PullUp or \a PullDown.
 Debouncer::Debouncer(PinName pin, PinMode mode)
-    : in(pin, mode), now(mode == PullUp), previous(mode == PullUp ? -1 : 0)
+    : in(pin, mode), previous(mode == PullUp ? -1 : 0), now(mode == PullUp)
 {
     samples(); period();
 }
 
 //! Set the number of identical samples needed to regard the input as stable.
 //! \note Limited to at most 32 samples.
-Debouncer &Debouncer::samples(int n)
+Debouncer &Debouncer::samples(uint8_t n)
 {
     _samples = n;
     return *this;