-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlidePot.hpp
More file actions
65 lines (56 loc) · 1.14 KB
/
SlidePot.hpp
File metadata and controls
65 lines (56 loc) · 1.14 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 SLIDEPOT_HPP
#define SLIDEPOT_HPP
class SlidePot
{
public:
SlidePot(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;
};
SlidePot::SlidePot(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 SlidePot::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 SlidePot::getCommand()
{
return _command;
}
inline byte SlidePot::getControl()
{
return _control;
}
inline byte SlidePot::getChannel()
{
return _channel;
}
#endif // SLIDEPOT_HPP