Library for debouncing inputs, originally by Andres Mora Bedoya. Updated to include PinMode capability and class documentation.
Fork of DebouncedIn by
Diff: DebouncedIn.h
- Revision:
- 1:7b8a80c09b8c
- Parent:
- 0:dc1131de43e8
- Child:
- 2:261228f701a1
--- a/DebouncedIn.h Tue Nov 05 19:29:03 2013 +0000 +++ b/DebouncedIn.h Wed Oct 08 14:44:47 2014 +0000 @@ -1,14 +1,62 @@ +/** + * DebouncedIn class version 1.0 + * Created by Andres Moya Bedoya, updated by Ben Faucher + */ + #include "mbed.h" - + +#ifndef _DEBOUNCED_IN_H_ +#define _DEBOUNCED_IN_H_ + +/** + * DebouncedIn object, uses software tickers to debounce mechanical inputs. + */ + class DebouncedIn { public: + /** Create a DebouncedIn connected to the specified pin + * + * @param in DigitalIn pin to connect to + * @param mode (optional) Set pull mode - PullUp, PullDown, PullNone, OpenDrain + */ DebouncedIn(PinName in); + DebouncedIn(PinName in, PinMode mode); + /** Read the input state, represented as 0 or 1 (int) + * + * @returns + * An integer representing the state of the input pin, + * 0 for logical 0, 1 for logical 1 + */ int read (void); + + /** An operator shorthand for read() + */ operator int(); + /** Register the input changing from low to high (int) + * + * @returns + * An integer representing if the input changed from low to high, + * 0 for logical 0, 1 for logical 1 + */ int rising(void); + + /** Register the input changing from high to low (int) + * + * @returns + * An integer representing if the input changed from high to low, + * 0 for logical 0, 1 for logical 1 + */ int falling(void); + + /** Check steady state of input (int) + * + * @returns + * An integer representing if the input has remained + * steady for a set amount of time, + * 0 for logical 0, 1 for logical 1 + */ int steady(void); private : @@ -27,4 +75,6 @@ int _falling_flag; int _state_counter; - }; \ No newline at end of file + }; + +#endif \ No newline at end of file