-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.pde.pi
57 lines (47 loc) · 1.14 KB
/
io.pde.pi
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
int rotaryA = 0;
int rotaryB = 0;
int newState = 0;
int lastState = 0;
int pinA = 27;
int pinB = 17;
// watch pins
void updatePinA(int pin) {
GPIO.noInterrupts();
rotaryA = GPIO.digitalRead(pinA);
updatePosition();
GPIO.interrupts();
}
void updatePinB(int pin) {
GPIO.noInterrupts();
rotaryB = GPIO.digitalRead(pinB);
updatePosition();
GPIO.interrupts();
}
// update position based on pins
void updatePosition() {
int xorVal = rotaryA ^ rotaryB;
// Get the new rotary encoder state
int newState = (rotaryA * 4) + (rotaryB * 2) + (xorVal * 1);
// Get the delta (difference) between the previous state and the new state
int delta = (newState - lastState) % 4;
// Store the state for next time around
lastState = newState;
//delta:
// 0 = no change
// 1 = one step clockwise
// 2 = two steps in either direction
// 3 = one step counter clockwise
switch(delta) {
case 1:
playheadManager.modifyPositionBy(-1);
//console.log(count);
break;
case 3:
playheadManager.modifyPositionBy(1);
//console.log(count);
break;
case 2:
//console.log('-');
break;
}
}