-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITSHServo.h
56 lines (48 loc) · 1.41 KB
/
ITSHServo.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
#include "Servo.h"
#include "Arduino.h"
class ITSHServoMove {
protected:
int _start;
int _current;
int _target;
public:
ITSHServoMove(int start, int target) : _start(start), _target(target), _current(start) {}
virtual ~ITSHServoMove() {}
virtual int nextPosition() = 0;
virtual boolean isDone();
};
class ITSHServoMoveLinear : public ITSHServoMove {
public:
ITSHServoMoveLinear(int start, int target) : ITSHServoMove(start, target) {}
virtual ~ITSHServoMoveLinear() {}
virtual int nextPosition();
};
class ITSHServoMoveEasing : public ITSHServoMoveLinear {
protected:
int _step;
int sineEaseInOut(int t, int b, int c, int d);
public:
ITSHServoMoveEasing(int start, int target) : ITSHServoMoveLinear(start, target), _step(0) {}
virtual ~ITSHServoMoveEasing() {}
virtual int nextPosition();
};
class ITSHServo {
private:
Servo _servo;
const int _min;
const int _max;
const int _home;
const int _pin;
int _currentPosition;
ITSHServoMove* _moveStrategy;
void updatePosition(int position);
public:
ITSHServo(int pin, int min, int max, int home) : _pin(pin), _min(min), _max(max), _home(home), _currentPosition(-1) {}
~ITSHServo();
void moveTo(int end, boolean easing);
void setup();
/**
* Wird in jeder Loop aufgerufen. Liefert true, wenn der Servo eine Bewegung durchgeführt hat.
*/
boolean loop();
};