forked from exshonda/ZumoShield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pushbutton.h
70 lines (54 loc) · 1.62 KB
/
Pushbutton.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*! \file Pushbutton.h
*
* See the Pushbutton class reference for more information about this library.
*
* \class Pushbutton Pushbutton.h
* \brief Read button presses and releases with debouncing
*
*/
#ifndef Pushbutton_h
#define Pushbutton_h
#include <Arduino.h>
#define ZUMO_BUTTON 12
#define PULL_UP_DISABLED 0
#define PULL_UP_ENABLED 1
#define DEFAULT_STATE_LOW 0
#define DEFAULT_STATE_HIGH 1
class Pushbutton
{
public:
// constructor; takes arguments specifying whether to enable internal pull-up
// and the default state of the pin that the button is connected to
Pushbutton(unsigned char pin, unsigned char pullUp = PULL_UP_ENABLED, unsigned char defaultState = DEFAULT_STATE_HIGH);
// wait for button to be pressed, released, or pressed and released
void waitForPress();
void waitForRelease();
void waitForButton();
// indicates whether button is currently pressed
boolean isPressed();
// more complex functions that return true once for each button transition
// from released to pressed or pressed to released
boolean getSingleDebouncedPress();
boolean getSingleDebouncedRelease();
private:
unsigned char _pin;
unsigned char _pullUp;
unsigned char _defaultState;
unsigned char gsdpState;
unsigned char gsdrState;
unsigned int gsdpPrevTimeMillis;
unsigned int gsdrPrevTimeMillis;
boolean initialized;
inline void init()
{
if (!initialized)
{
initialized = true;
init2();
}
}
// initializes I/O pin for use as button input
void init2();
boolean _isPressed();
};
#endif