class of Buttons -isPressed -wasPressed -notPressed -LongPress (Timer)
Diff: Button.h
- Revision:
- 5:6eefa28ac3fd
- Parent:
- 4:3b94400f2894
- Child:
- 8:6c8a00baae91
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Button.h Thu Jan 24 12:27:33 2019 +0000 @@ -0,0 +1,41 @@ +#ifndef MBED_BUTTON_H +#define MBED_BUTTON_H + +#include "mbed.h" + +#define NUMCYCLE 10 +#define PRESSED 0 +#define NOT_PRESSED 1 + +class Button +{ + + public: // public + Button(PinName pBtn, PinMode pBtnMode, float Time = 0); // constructor + void init(); // initialisation + void polling(uint8_t *iNumBtn = NULL); // polls and debounce the button + bool isPressed(); // bool value if button is pressed or not + bool wasPressed(); // + bool isLongPress(); + + + private: // private + bool bIsPressed; // current pressing state + bool bWasPressed; // last pressenig state + bool bLongPress; // if current pressing state is an long press + bool bNewState; // current state/value of button + bool bOldState; // previous state/value of button + bool bBtnNewAction; // flag if an action is occur + int iNumCycle; // cycle counter + float fTime; // if constructor creates an timer, this flag is set high + + + void setLongPressFlag(); + + DigitalIn *pin; // Input pin for Button + Timeout *timer; // Timer, to set a Flag for secound Mode + +}; + + +#endif