Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Button.h
Go to the documentation of this file.
1
19
#ifndef BUTTON_H
20
#define BUTTON_H
21
22
#include "
GPIO.h
"
23
30
template
<BOARD::pin_t PIN, u
int
16_t DEBOUNCE = 50>
31
class
Button
{
32
public
:
37
Button
() :
38
m_timestamp
(0),
39
m_state
(true)
40
{
41
m_pin
.input().pullup();
42
}
43
50
bool
ischanged
()
51
{
52
// Check if debounce time limit has elapsed
53
if
(millis() -
m_timestamp
< DEBOUNCE)
return
(
false
);
54
m_timestamp
= millis();
55
56
// Check for the pin state has changed
57
bool
state =
m_pin
;
58
if
(state ==
m_state
)
return
(
false
);
59
m_state
= state;
60
return
(
true
);
61
}
62
67
bool
read
()
68
{
69
return
(
m_state
);
70
}
71
76
operator
bool()
77
__attribute__((always_inline))
78
{
79
return
(
read
());
80
}
81
86
uint16_t
timestamp
()
87
{
88
return
(
m_timestamp
);
89
}
90
91
protected
:
93
GPIO<PIN>
m_pin
;
94
96
uint16_t
m_timestamp
;
97
99
bool
m_state
;
100
};
101
102
#endif
Button
Definition:
Button.h:31
Button::m_timestamp
uint16_t m_timestamp
Definition:
Button.h:96
Button::Button
Button()
Definition:
Button.h:37
GPIO.h
Button::ischanged
bool ischanged()
Definition:
Button.h:50
Button::read
bool read()
Definition:
Button.h:67
Button::m_state
bool m_state
Definition:
Button.h:99
GPIO
Definition:
GPIO.h:31
Button::m_pin
GPIO< PIN > m_pin
Definition:
Button.h:93
Button::timestamp
uint16_t timestamp()
Definition:
Button.h:86
src
Button.h
Generated on Sat Oct 14 2017 16:03:22 for Arduino-GPIO by
1.8.11