-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTenBit_Encoder_Eest.ino
60 lines (51 loc) · 1.03 KB
/
TenBit_Encoder_Eest.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
#define BITS 10
#define LSB
int pins_MSB_2_LSB[] = {53,51,41,39,37,35,49,47,45,43};
int arr[]={1,2,4,8,16,32,64,128,256,512};
void greytobinary(int *a, int count)
{
int i;
for(i = count - 2; i >= 0; i--)
{
a[i] = a[i]^a[i+1];
}
}
int binarytodecimal(int *a, int count)
{
int sum=0,i;
for(i= 0;i < BITS;i++)
sum = sum + (arr[i]*a[i]);
return sum;
}
void setup(){
int i;
for (i = 0;i<BITS;i++){
pinMode(pins_MSB_2_LSB[i], INPUT_PULLUP);
}
Serial.begin(9600);
Serial.print("ready\n");
}
void loop(){
int rawValues[BITS];
int i, j;
int result;
j = BITS - 1;
for (i = 0;i<BITS;i++){
int readVal;
readVal = !digitalRead(pins_MSB_2_LSB[i]);
rawValues[j] = readVal;
j--;
}
for(j = BITS -1; j >=0; j--){
Serial.print(rawValues[j]);
}
greytobinary(rawValues, BITS);
Serial.print("\t");
for(j = BITS-1; j>=0; j--){
Serial.print(rawValues[j]);
}
result = binarytodecimal(rawValues, BITS);
Serial.print("\t");
Serial.println(result);
delay(100);
}