-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotaryPot.hpp
More file actions
65 lines (56 loc) · 1.15 KB
/
RotaryPot.hpp
File metadata and controls
65 lines (56 loc) · 1.15 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
#ifndef ROTARYPOT_HPP
#define ROTARYPOT_HPP
class RotaryPot
{
public:
RotaryPot(byte pin, byte command, byte control, byte channel);
inline byte getCompValue();
inline byte getCommand();
inline byte getControl();
inline byte getChannel();
private:
byte _pin;
byte _muxpin;
byte _numMuxPins;
byte _control;
byte _command;
byte _channel;
int _value;
int _oldValue;
bool _changed;
byte _enablepin;
};
RotaryPot::RotaryPot(byte pin, byte command, byte control, byte channel):
_pin(pin),
_control(control),
_command(command),
_channel(channel)
{
_value = analogRead(_pin);
_oldValue = _value;
_value = _value >> 3;
}
byte RotaryPot::getCompValue()
{
_value = analogRead(_pin);
int tmp = (_oldValue - _value);
if (tmp >= 8 || tmp <= -8) {
_oldValue = _value >> 3;
_oldValue = _oldValue << 3;
return _value >> 3;
}
return 255;
}
inline byte RotaryPot::getCommand()
{
return _command;
}
inline byte RotaryPot::getControl()
{
return _control;
}
inline byte RotaryPot::getChannel()
{
return _channel;
}
#endif // ROTARYPOT_HPP