-
Notifications
You must be signed in to change notification settings - Fork 0
/
Encoder.cpp
executable file
·60 lines (52 loc) · 1.12 KB
/
Encoder.cpp
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
/*
* Encoder.cpp
*
* Created on: Dec 2, 2009
* Author: asher
*/
#include "Encoder.h"
Encoder::Encoder() {
// TODO Auto-generated constructor stub
clearCount();
}
void Encoder::clearCount(){
encoderCount=0;
}
void Encoder::update(char channelA, char channelB){
if ((priorA == 0) && (channelA == 1)) {
if (channelB == 0) {
encoderCount--;
} else {
encoderCount++;
}
}
if ((priorA == 1) && (channelA == 0)) {
if (channelB == 0) {
encoderCount++;
} else {
encoderCount--;
}
}
priorA = channelA;
if ((priorB == 0) && (channelB == 1)) {
if (channelA == 0) {
encoderCount++;
} else {
encoderCount--;
}
}
if ((priorB == 1) && (channelB == 0)) {
if (channelA == 0) {
encoderCount--;
} else {
encoderCount++;
}
}
priorB = channelB;
}
int Encoder::count(){
return encoderCount;
}
Encoder::~Encoder() {
// TODO Auto-generated destructor stub
}