forked from PhamDuyAnh/Arduino_Plasma_THC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_encoder.ino
99 lines (90 loc) · 1.98 KB
/
_encoder.ino
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//Encoder Interrupt time require <2us
boolean A, B, lastA, lastB;
boolean ButtonOk, ButtonStat, lastButtonStat;
void Setup_Encoder()
{
pinMode(encoderPinA, INPUT);
pinMode(encoderPinB, INPUT);
pinMode(buttonPin, INPUT);
attachInterrupt(0, doEncoder, CHANGE);
}
//attachInterrupt(0, doEncoder, CHANGE);
//2x Quadrature Encoder
/*
void doEncoder()
{
A = bitRead(PIND, 2);
B = bitRead(PIND, 3);
if ((A != lastA) & (B != lastB))
{
if (A ^ B) Vset ++;
else Vset --;
}
lastA = A;
lastB = B;
}
*/
//attachInterrupt(0, doEncoder, CHANGE);
//1x Quadrature Encoder
void doEncoder()
{
A = bitRead(PIND, 2);
B = bitRead(PIND, 3);
if ((A != lastA) & (B != lastB))
{
if (A)
if (A = B) encoderVal ++;
else encoderVal --;
LCDtime = 0;
}
lastA = A;
lastB = B;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// Button
void checkButton()
{
ButtonStat = bitRead(PIND, 4);
if (ButtonStat != lastButtonStat)
{
if (!ButtonStat) ButtonOk = true;
lastButtonStat = ButtonStat;
}
}
void checkMenu()
{
if (ButtonOk)
{
Serial.print(menu);
Serial.println(" Button");
ButtonOk = false;
LCDtime = 0;
if (menu == 0) menu = 1;
else if (menu == 1)
{
if (pos == 0) menu = 0;
else if (pos == 1) menu = 11;
else if (pos == 2) menu = 12;
}
else if (menu == 11)
{
if (pos == 0) menu = 1;
else if (pos == 1) menu = 111;
else if (pos == 2) menu = 112;
else if (pos == 3) menu = 113;
else if (pos == 4) menu = 114;
}
else if (menu == 111) menu = 11;
else if (menu == 112) menu = 11;
else if (menu == 113) menu = 11;
else if (menu == 12)
{
menu = 1;
}
if (menu == 0) encoderVal = SetV;
else if (menu == 111) encoderVal = DT;
else if (menu == 112) encoderVal = HyS;
else if (menu == 113) encoderVal = StV;
else encoderVal = 0;
}
}