-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.hpp
More file actions
76 lines (62 loc) · 1.29 KB
/
Button.hpp
File metadata and controls
76 lines (62 loc) · 1.29 KB
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
71
72
73
74
75
76
#ifndef BUTTON_HPP
#define BUTTON_HPP
#include <Bounce.h>
class Button
{
public:
Button(byte pin, command_t command, byte value, byte channel, byte debounce);
button_state_t getCompValue();
inline byte getCommand();
inline byte getValue();
inline byte getChannel();
inline byte getToggle();
inline void setToggle(byte toggle);
private:
byte _pin;
byte _muxpin;
byte _numMuxPins;
command_t _command;
byte _value;
byte _channel;
byte _debounce;
byte _toggle;
Bounce _button;
};
Button::Button(byte pin, command_t command, byte value, byte channel, byte debounce):
_pin(pin),
_command(command),
_value(value),
_channel(channel),
_debounce(debounce),
_button(Bounce(pin, debounce))
{
pinMode(_pin, INPUT_PULLUP);
_toggle = 0;
}
button_state_t Button::getCompValue()
{
_button.update();
if (_button.fallingEdge()) return PRESSED;
if (_button.risingEdge()) return NOT_PRESSED;
}
inline byte Button::getCommand()
{
return _command;
}
inline byte Button::getValue()
{
return _value;
}
inline byte Button::getChannel()
{
return _channel;
}
inline byte Button::getToggle()
{
return _toggle;
}
inline void Button::setToggle(byte toggle)
{
_toggle = toggle;
}
#endif // BUTTON_HPP