David Möschwitzer / button
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Button.h Source File

Button.h

00001 #ifndef MBED_BUTTON_H
00002 #define MBED_BUTTON_H
00003 
00004 #include "mbed.h"
00005 
00006 #define NUMCYCLE    10
00007 #define PRESSED     0
00008 #define NOT_PRESSED 1
00009 
00010 class Button
00011 {
00012 
00013     public:                                                                     // public
00014         Button(PinName pBtn, PinMode  pBtnMode, float Time = 0);                // constructor
00015         void init();                                                            // initialisation
00016         void polling(uint8_t *iNumBtn = NULL);                                  // polls and debounce the button 
00017         bool isPressed();                                                       // bool value if button is pressed or not
00018         bool wasPressed();                                                      //
00019         bool isLongPress();
00020     
00021     
00022     private:                                                                    // private
00023         bool bIsPressed;                                                        // current pressing state
00024         bool bWasPressed;                                                       // last pressenig state
00025         bool bLongPress;                                                        // if current pressing state is an long press
00026         bool bNewState;                                                         // current state/value of button
00027         bool bOldState;                                                         // previous state/value of button
00028         bool bBtnNewAction;                                                     // flag if an action is occur
00029         int iNumCycle;                                                          // cycle counter
00030         float fTime;                                                            // if constructor creates an timer, this flag is set high
00031     
00032     
00033         void setLongPressFlag();
00034         
00035         DigitalIn *pin;                                                         // Input pin for Button   
00036         Timeout *timer;                                                         // Timer, to set a Flag for secound Mode
00037         
00038 };
00039 
00040 
00041 #endif