button procedure library
Revision 1:20c8438edaee, committed 2014-08-06
- Comitter:
- ChuckTimber
- Date:
- Wed Aug 06 23:44:39 2014 +0000
- Parent:
- 0:f57033bb0e05
- Child:
- 2:df827b705b98
- Commit message:
- BTN_SAMPLING_PERIOD defined.
Changed in this revision
button.cpp | Show annotated file Show diff for this revision Revisions of this file |
button.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/button.cpp Sun Jul 13 05:12:21 2014 +0000 +++ b/button.cpp Wed Aug 06 23:44:39 2014 +0000 @@ -1,21 +1,41 @@ #include "button.h" #include "mbed.h" -/** class to make sound with a buzzer, based on a PwmOut - * The class use a timeout to switch off the sound - it is not blocking while making noise +/** class to handle button input + * The class use DigitalIn and Ticker * * Example: * @code + * // Button sample + * #include "mbed.h" + * #include "button.h" + * + * BTN btn(dp13); + * + * int main() + * { + * int mode = 0; + * int value; + * + * btn.CMD = 0; + * while(1) { + * if(btn.CMD) { + * mode++; + * btn.CMD = 0; + * srand( time(NULL) ); + * } + * if (mode % 2) value = rand(); + * } + * } * @endcode */ using namespace mbed; - // constructor - /** Create a Beep object connected to the specified PwmOut pin - * - * @param pin PwmOut pin to connect to - */ +// private function +/** sample_btn input and process + * + */ void BTN::sample_btn() { unsigned char a, b; @@ -31,7 +51,12 @@ FIL = a; } + // constructor + /** Create a BTN object connected to a DigtalIn pin + * + * @param pin - DigitalIn pin connected to the switch + */ BTN::BTN(PinName pin) : _Pin(pin) { CMD = STAT = FIL = 0; - _Tick.attach(this, &BTN::sample_btn, 0.01); + _Tick.attach(this, &BTN::sample_btn, BTN_SAMPLING_PERIOD); }
--- a/button.h Sun Jul 13 05:12:21 2014 +0000 +++ b/button.h Wed Aug 06 23:44:39 2014 +0000 @@ -3,19 +3,43 @@ #include "mbed.h" -/** class to make - * The class use +/** class to handle button input + * The class use DigitalIn and Ticker + * + * Refered to: http://elm-chan.org/docs/tec/te03.html * * Example: * @code + * // Button sample + * #include "mbed.h" + * #include "button.h" + * + * BTN btn(dp13); + * + * int main() + * { + * int mode = 0; + * int value; + * + * btn.CMD = 0; + * while(1) { + * if(btn.CMD) { + * mode++; + * btn.CMD = 0; + * srand( time(NULL) ); + * } + * if (mode % 2) value = rand(); + * } + * } * @endcode */ +#define BTN_SAMPLING_PERIOD 0.01 namespace mbed { /* Class: BTN - * A class witch uses + * A class which uses DigitalIn and Ticker */ class BTN {