-
Notifications
You must be signed in to change notification settings - Fork 0
/
Encoders.cpp
91 lines (57 loc) · 1.46 KB
/
Encoders.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
61
62
63
64
65
66
67
68
#include "Encoders.h"
#include <Bela.h>
#include "global.h"
Encoders::Encoders(){
mIncr = 0;
mIncr_prev = 0;
}
void Encoders::setup(int index, int FrameA, int FrameB){
EncNumber = index;
mFrameA = FrameA;
mFrameB = FrameB;
}
void Encoders::read(BelaContext *context)
{
mPinA_prev = mPinA;
mPinB_prev = mPinB;
mPinA = digitalRead(context,mFrameA,SerOut2);
mPinB = digitalRead(context,mFrameB,SerOut2);
if (gCount == 0){
mPinA_prev = mPinA;
mPinB_prev = mPinB;
}
if (mPinA != mPinA_prev || mPinB != mPinB_prev )
{
if (mPinB == 1)
{
if (mPinA > mPinA_prev) mIncr++;
if (mPinA < mPinA_prev) mIncr--;
}
if (mPinB == 0)
{
if (mPinA > mPinA_prev) mIncr--;
if (mPinA < mPinA_prev) mIncr++;
}
if (mPinA == 0)
{
if (mPinB > mPinB_prev) mIncr++;
if (mPinB < mPinB_prev) mIncr--;
}
if (mPinA == 1)
{
if (mPinB > mPinB_prev) mIncr--;
if (mPinB < mPinB_prev) mIncr++;
}
}
}
float Encoders::getIncr()
{
mIncr_prev = mIncr;
mIncr = 0;
return mIncr_prev;
//return mIncr[index];
}
void Encoders::update(Looper Loop, int ChSel, int ModeSel){
Loop.channel[ChSel].mode[ModeSel].param[EncNumber].update(mIncr);
mIncr = 0;
}