-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncoderWing.ino
More file actions
41 lines (33 loc) · 853 Bytes
/
EncoderWing.ino
File metadata and controls
41 lines (33 loc) · 853 Bytes
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
#define N 6
char carattere[12] = {'a','b','c','d','e','f','g','h','i','l','m','n'};
const int clk[N] = {2, 4, 6, 8, 10, 12};
const int data[N] = {3, 5, 7, 9, 11, 13};
int State[N];
int LastState[N];
int i;
void setup() {
//Define the pins as inputs
for(i=0; i<N; i++){
pinMode (clk[i],INPUT);
pinMode (data[i],INPUT);
}
Serial.begin (9600);
// Reads the initial state of the clock pin
for(i=0; i<N; i++){
LastState[i] = digitalRead(clk[i]);
}
}
void loop() {
// Reads the "current" state of the clock pin
for(int i=0; i<N; i++){
State[i] = digitalRead(clk[i]);
if (State[i] != LastState[i]){
if (digitalRead(data[i]) != State[i]) {
Serial.write(carattere[i*2+1]);
} else {
Serial.write(carattere[i*2]);
}
LastState[i] = State[i];
}
}
}