-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCursor.ino
68 lines (44 loc) · 978 Bytes
/
Cursor.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
// Rotary Encoder Inputs
#define CLK 11
#define DT 12
#define SW 13
int Cursor(){
int btnState = digitalRead(SW);
int counter = 0;
int currentStateCLK;
int lastStateCLK = digitalRead(CLK);
while(1){//&& (millis() - lastButtonPress > 50)){
currentStateCLK = digitalRead(CLK);
if (currentStateCLK != lastStateCLK && currentStateCLK == 1){
if (digitalRead(DT) != currentStateCLK) {
counter --;
} else {
counter ++;
}
Serial.println(counter);
}
lastStateCLK = currentStateCLK;
// Read the button state
int btnState = digitalRead(SW);
//lastButtonPress = millis();
if(btnState == LOW){
break;
}
delay(1);
}
return counter;
}
void setup() {
// Set encoder pins as inputs
pinMode(CLK,INPUT);
pinMode(DT,INPUT);
pinMode(SW, INPUT_PULLUP);
// Setup Serial Monitor
Serial.begin(9600);
}
void loop() {
int cu = Cursor();
Serial.print("the cu selected is: ");
Serial.println(cu);
delay(1000);
}