@@ -33,42 +33,42 @@ class Button
33
33
34
34
// Returns true if the button state was pressed at the last call to read().
35
35
// Does not cause the button to be read.
36
- bool isPressed () {return m_state;}
36
+ bool isPressed () const {return m_state;}
37
37
38
38
// Returns true if the button state was released at the last call to read().
39
39
// Does not cause the button to be read.
40
- bool isReleased () {return !m_state;}
40
+ bool isReleased () const {return !m_state;}
41
41
42
42
// These functions check the button state to see if it changed
43
43
// between the last two reads and return true or false accordingly.
44
44
// These functions do not cause the button to be read.
45
- bool wasPressed () {return m_state && m_changed;}
46
- bool wasReleased () {return !m_state && m_changed;}
45
+ bool wasPressed () const {return m_state && m_changed;}
46
+ bool wasReleased () const {return !m_state && m_changed;}
47
47
48
48
// Returns true if the button state at the last call to read() was pressed,
49
49
// and has been in that state for at least the given number of milliseconds.
50
50
// This function does not cause the button to be read.
51
- bool pressedFor (uint32_t ms) {return m_state && m_time - m_lastChange >= ms;}
51
+ bool pressedFor (uint32_t ms) const {return m_state && m_time - m_lastChange >= ms;}
52
52
53
53
// Returns true if the button state at the last call to read() was released,
54
54
// and has been in that state for at least the given number of milliseconds.
55
55
// This function does not cause the button to be read.
56
- bool releasedFor (uint32_t ms) {return !m_state && m_time - m_lastChange >= ms;}
56
+ bool releasedFor (uint32_t ms) const {return !m_state && m_time - m_lastChange >= ms;}
57
57
58
58
// Returns the time in milliseconds (from millis) that the button last
59
59
// changed state.
60
- uint32_t lastChange () {return m_lastChange;}
60
+ uint32_t lastChange () const {return m_lastChange;}
61
61
62
62
private:
63
- uint8_t m_pin; // arduino pin number connected to button
64
- uint32_t m_dbTime; // debounce time (ms)
65
- bool m_puEnable; // internal pullup resistor enabled
66
- bool m_invert; // if true, interpret logic low as pressed, else interpret logic high as pressed
67
- bool m_state; // current button state, true=pressed
68
- bool m_lastState; // previous button state
69
- bool m_changed; // state changed since last read
70
- uint32_t m_time; // time of current state (ms from millis)
71
- uint32_t m_lastChange; // time of last state change (ms)
63
+ uint8_t m_pin; // arduino pin number connected to button
64
+ uint32_t m_dbTime; // debounce time (ms)
65
+ bool m_puEnable; // internal pullup resistor enabled
66
+ bool m_invert; // if true, interpret logic low as pressed, else interpret logic high as pressed
67
+ bool m_state = false ; // current button state, true=pressed
68
+ bool m_lastState = false ; // previous button state
69
+ bool m_changed = false ; // state changed since last read
70
+ uint32_t m_time = 0 ; // time of current state (ms from millis)
71
+ uint32_t m_lastChange = 0 ; // time of last state change (ms)
72
72
};
73
73
74
74
// a derived class for a "push-on, push-off" (toggle) type button.
@@ -97,13 +97,13 @@ class ToggleButton : public Button
97
97
}
98
98
99
99
// has the state changed?
100
- bool changed () {return m_changed;}
100
+ bool changed () const {return m_changed;}
101
101
102
102
// return the current state
103
- bool toggleState () {return m_toggleState;}
103
+ bool toggleState () const {return m_toggleState;}
104
104
105
105
private:
106
106
bool m_toggleState;
107
- bool m_changed;
107
+ bool m_changed = false ;
108
108
};
109
109
#endif
0 commit comments