-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaliberation.ino
executable file
·141 lines (123 loc) · 4.43 KB
/
caliberation.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//multiplication factors copy paste the values@#$%^&*#@$%^*&()&(^%$#
float multfactor[3][8] = {};
int subfactor[3][8] = {}; //subtraction factor
//float mtwo[3][2] = {};
//int stwo[3][2] = {};
int white_threshold = 900;
int black_threshold = 200;
//int opts_six_min[6][5] = {};//array of minimum values of big array
//int opts_two_min[2][5] = {};//array of minimum values of small array
void caliberation(){
int opts = 6;//number of opts in selected array
boolean selection_ok = false;
int pin = 0;
short index = 0;
Serial.println("Give 1 to 6 number to caliberate specific array");
while(!selection_ok){
index = Serial.parseInt();
if(index == 1 || index == 3 || index == 5) {
opts = 6;
selection_ok = true;
}
else if(index == 2 || index == 4 || index == 6) {
opts = 2;
selection_ok = true;
}
else {
Serial.println("Give a number between 1 and 6");
}
}
int opt_data[opts][5];//array for storing the 5 values for each opt
int sum_samples[opts];//sum of recorded 5 values
int average1[opts] ;//average values of the opts for one color black or white
int average2[opts] ;//average values of opts for another color
if(opts==6) {
switch(index){
case(1): pin = 0;break;
case(3): pin = 8; break;
case(5): pin = 16; break;
}
}
else {
switch(index){
case(2): pin = 0;break;
case(4): pin = 8; break;
case(6): pin = 16; break;
}
}
//Ask for white values or blacks
boolean color_selection = false;
boolean color = false;//will remain false for black color and will become true for white color
Serial.println("Give 1 for white range value recording or give 0 for black value recording");
while(!color_selection) {
int t = Serial.parseInt();
if(t==0) {
color_selection = true;
}
else if(t==1) {
color_selection = true;
color=true;
}
else {
Serial.println("give value 1 for white or 0 for black");
}
}
//begin taking data
for(int i= 0;i<5;i++){
int copy_pin = pin;
for(int j= 0;j<opts;j++){
copy_pin++;
if(opts==2){copy_pin += 6;}
int val = reading(pin);
sum_samples[j] += val;
if(color){if(val<white_threshold){Serial.println();
Serial.print("Opt gave wrong value-");
Serial.print(pin);}}
else{if(val>black_threshold){Serial.println();
Serial.print("Opt gave wrong value-");
Serial.print(pin);}}
delay(200);
}
}
Serial.println();
for(int i = 0;i<opts;i++){average1[i] = sum_samples[i]/5;Serial.print(average1[i]);Serial.print(" ");}//count average values of recorded values
//code repetion for another set of values
for(int i = 0; i < opts; i++){sum_samples[i] = 0;}
color_selection = false;
color = false;//will remain false for black color and will become true for white color
Serial.println("Give 1 for white range value recording or give 0 for black value recording");
while(!color_selection){
int t = Serial.parseInt();
if(t==0){color_selection = true;}
else if(t==1){color_selection = true;color=true;}
else{Serial.println("give value 1 for white or 0 for black");}
}
//begin taking data
for(int i= 0;i<5;i++){
int copy_pin = pin;
for(int j= 0;j<opts;j++){
copy_pin++;
if(opts==2){pin += 6;}
int val = reading(copy_pin);
sum_samples[j] += val;
if(color){if(val<white_threshold){Serial.println();
Serial.print("Opt gave wrong value-");
Serial.print(pin);}}
else{if(val>black_threshold){Serial.println();
Serial.print("Opt gave wrong value-");
Serial.print(pin);}}
delay(200);
}
}
Serial.println();
for(int i = 0;i<opts;i++){average2[i] = sum_samples[i]/5;Serial.print(average2[i]);Serial.print(" ");}
//calculate addition and multiplication factors now\
// int addition_factor[opts] = {};
//float multiplication_factor[opts] = {};
Serial.println("Multiplication Factors");
for(int i = 0; i<opts; i++){
int j = 1024/abs(average2[i]-average1[i]);
Serial.print(j);
Serial.print(" ");
}
}