Arduino Universal Inputs
A collection of libraries for managing/processing input devices on Arduino.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator
IButton.h
Go to the documentation of this file.
1 
3 #ifndef _ARDUINOUNIVERSALINPUTS_IBUTTON_H
4 #define _ARDUINOUNIVERSALINPUTS_IBUTTON_H
5 
6 #include "IInputDevice.h"
7 
8 #include "Arduino.h"
9 
14 class IButton : public IInputDevice
15 {
16 public:
17  IButton(inputid_t id, inputtime_t debounceDelay = 50);
18  virtual ~IButton();
19 
23  inputtype_t type() const { return UIT_BUTTON; }
24 
25  bool setDebounceDelay(inputtime_t debounce);
26 
31  inputtime_t getDebounceDelay() const { return m_debounceDelay; }
32 
33  bool poll();
34 
39  bool isActive() const { return m_active; }
40 
45  inputtime_t lastStateChange() const { return m_lastStateChange; }
46 
51  inputtime_t lastActiveDuration() const { return m_lastActiveDuration; }
52 
53 protected:
58  virtual uint8_t getPhysicalState() const = 0;
59 
60 private:
61  bool m_active;
62 
63  inputtime_t m_lastStateChange;
64  inputtime_t m_lastActiveDuration;
65 
66  inputtime_t m_debounceDelay;
67 };
68 
69 #endif
bool isActive() const
Determines if the button is currently active.
Definition: IButton.h:39
Represents an input device.
Definition: IInputDevice.h:14
uint16_t inputid_t
Holds the value of a device ID.
Definition: UniversalInputTypes.h:13
inputtime_t lastActiveDuration() const
Returns the duration for which the button was last active.
Definition: IButton.h:51
inputtype_t type() const
Retrieves the type of this device.
Definition: IButton.h:23
inputtime_t getDebounceDelay() const
Gets the current debounce delay time.
Definition: IButton.h:31
virtual uint8_t getPhysicalState() const =0
Gets the current physical state of the button.
Buttons inheriting from IButton.
Definition: UniversalInputTypes.h:39
bool poll()
Polls this input device for change.
Definition: IButton.cpp:38
inputtype_t
Enumeration of all input device types.
Definition: UniversalInputTypes.h:37
Represents a two state button.
Definition: IButton.h:14
IButton(inputid_t id, inputtime_t debounceDelay=50)
Creates a new button.
Definition: IButton.cpp:10
uint32_t inputtime_t
Holds the value of a timestap.
Definition: UniversalInputTypes.h:25
bool setDebounceDelay(inputtime_t debounce)
Sets the debounce delay time.
Definition: IButton.cpp:26
inputtime_t lastStateChange() const
Returns the time of the last state change.
Definition: IButton.h:45