button procedure library
button.cpp
- Committer:
- ChuckTimber
- Date:
- 2014-08-07
- Revision:
- 3:1c47d318e457
- Parent:
- 2:df827b705b98
- Child:
- 4:d6a45bd85a43
File content as of revision 3:1c47d318e457:
#include "button.h" #include "mbed.h" /** * @file button.cpp * Project button handling Library * @brief button handling library for mbed * @version 1.0 * @author Chuck Timber * @date 07/08/2014 */ /** 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; // private function /** sample_btn input and process */ void BTN::sample_btn() { unsigned char a, b; a = _Pin; if (a == FIL) { b = STAT; STAT = a; b = (b ^ a) & a; if (b) CMD = b; } 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, BTN_SAMPLING_PERIOD); }