-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputArm.h
61 lines (46 loc) · 1.26 KB
/
InputArm.h
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
#ifndef INPUTARM_H_INCL
#define INPUTARM_H_INCL
#include "mimic.h"
#define DEFAULT_SAMPLES 1
class InputArm : public Arm {
protected:
int samples;
uint16_t analogReadAvg(int pin, int num = 0) {
long total = 0;
if (num == 0)
num = samples;
for (int i=0; i < num; i++)
total += analogRead(pin);
return total / num;
}
public:
InputArm() = delete;
InputArm(int pinch_pin, int wrist_pin, int elbow_pin, int waist_pin, Limits &limits) :
Arm(pinch_pin, wrist_pin, elbow_pin, waist_pin, limits),
samples(DEFAULT_SAMPLES) {
pinMode(pinchPin, INPUT);
pinMode(wristPin, INPUT);
pinMode(elbowPin, INPUT);
pinMode(waistPin, INPUT);
}
uint16_t readPinch() {
return pinch = clip(analogReadAvg(pinchPin), range.a.pinch, range.b.pinch);
}
uint16_t readWrist() {
return wrist = clip(analogReadAvg(wristPin), range.a.wrist, range.b.wrist);
}
uint16_t readElbow() {
return elbow = clip(analogReadAvg(elbowPin), range.a.elbow, range.b.elbow);
}
uint16_t readWaist() {
return waist = clip(analogReadAvg(waistPin), range.a.waist, range.b.waist);
}
InputArm &read() {
readPinch();
readWrist();
readElbow();
readWaist();
return *this;
}
};
#endif // #ifndef INPUTARM_H_INCL