class of Buttons -isPressed -wasPressed -notPressed -LongPress (Timer)
button.h@0:8625b4741933, 2018-11-30 (annotated)
- Committer:
- x1dmoesc
- Date:
- Fri Nov 30 15:46:00 2018 +0000
- Revision:
- 0:8625b4741933
- Child:
- 1:e9d0d9b29acc
Stand_30.11.2018
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
x1dmoesc | 0:8625b4741933 | 1 | #ifndef MBED_BUTTON_H |
x1dmoesc | 0:8625b4741933 | 2 | #define MBED_BUTTON_H |
x1dmoesc | 0:8625b4741933 | 3 | |
x1dmoesc | 0:8625b4741933 | 4 | #include "mbed.h" |
x1dmoesc | 0:8625b4741933 | 5 | |
x1dmoesc | 0:8625b4741933 | 6 | #define NUMCYCLE 10 |
x1dmoesc | 0:8625b4741933 | 7 | #define PRESSED 0 |
x1dmoesc | 0:8625b4741933 | 8 | #define NOT_PRESSED 1 |
x1dmoesc | 0:8625b4741933 | 9 | |
x1dmoesc | 0:8625b4741933 | 10 | class button |
x1dmoesc | 0:8625b4741933 | 11 | { |
x1dmoesc | 0:8625b4741933 | 12 | |
x1dmoesc | 0:8625b4741933 | 13 | public: // public |
x1dmoesc | 0:8625b4741933 | 14 | button(PinName pBtn, PinMode pBtnMode); // constructor |
x1dmoesc | 0:8625b4741933 | 15 | void init(); // initialisation |
x1dmoesc | 0:8625b4741933 | 16 | void polling(); // polls and debounce the button |
x1dmoesc | 0:8625b4741933 | 17 | bool isPressed(); // bool value if button is pressed or not |
x1dmoesc | 0:8625b4741933 | 18 | bool wasPressed(); // |
x1dmoesc | 0:8625b4741933 | 19 | |
x1dmoesc | 0:8625b4741933 | 20 | |
x1dmoesc | 0:8625b4741933 | 21 | |
x1dmoesc | 0:8625b4741933 | 22 | private: // private |
x1dmoesc | 0:8625b4741933 | 23 | bool bIsPressed; |
x1dmoesc | 0:8625b4741933 | 24 | bool bWasPressed; |
x1dmoesc | 0:8625b4741933 | 25 | bool bNewState; // current state/value of button |
x1dmoesc | 0:8625b4741933 | 26 | bool bOldState; // previous state/value of button |
x1dmoesc | 0:8625b4741933 | 27 | bool bBtnNewAction; // flag if an action is occur |
x1dmoesc | 0:8625b4741933 | 28 | int iNumCycle; // cycle counter |
x1dmoesc | 0:8625b4741933 | 29 | |
x1dmoesc | 0:8625b4741933 | 30 | DigitalIn *pin; |
x1dmoesc | 0:8625b4741933 | 31 | |
x1dmoesc | 0:8625b4741933 | 32 | }; |
x1dmoesc | 0:8625b4741933 | 33 | |
x1dmoesc | 0:8625b4741933 | 34 | |
x1dmoesc | 0:8625b4741933 | 35 | #endif |