-
Notifications
You must be signed in to change notification settings - Fork 3
/
DBALIC_V2.ino
180 lines (160 loc) · 4.29 KB
/
DBALIC_V2.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#define SEN1 36
#define SEN2 39
#define SEN3 34
#define SEN4 35
#define L1 16
#define L2 17
#define L3 18
#define L4 19
long sum1, sum2, sum3, sum4;
long a, b, c, d;
void setup() {
Serial.begin(115200);
pinMode(SEN1, INPUT);
pinMode(SEN2, INPUT);
pinMode(SEN3, INPUT);
pinMode(SEN4, INPUT);
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
}
void loop() {
sum1 = 0;
a = 0;
for (int i = 0; i <= 1000; i++) {
int val1 = analogRead(SEN1);
sum1 = sum1 + val1;
}
a = sum1 / 1000;
Serial.print("Value from SEN1: ");
Serial.println(a);
sum2 = 0;
b = 0;
for (int i = 0; i <= 1000; i++) {
int val2 = analogRead(SEN2);
sum2 = sum2 + val2;
}
b = sum2 / 1000;
Serial.print("Value from SEN2: ");
Serial.println(b);
sum3 = 0;
c = 0;
for (int i = 0; i <= 1000; i++) {
int val3 = analogRead(SEN3);
sum3 = sum3 + val3;
}
c = sum3 / 1000;
Serial.print("Value from SEN3: ");
Serial.println(c);
sum4 = 0;
d = 0;
for (int i = 0; i <= 1000; i++) {
int val4 = analogRead(SEN4);
sum4 = sum4 + val4;
}
d = sum4 / 1000;
Serial.print("Value from SEN4: ");
Serial.println(d);
delay(200);
if (a == 0) {
analogWrite(L1, 0);
} else {
if ((a < 402) && (a > 0)) {
analogWrite(L1, 25);
} else if ((a < 804) && (a >= 402)) {
analogWrite(L1, 50);
} else if ((a < 1206) && (a >= 804)) {
analogWrite(L1, 75);
} else if ((a < 1608) && (a >= 1206)) {
analogWrite(L1, 100);
} else if ((a < 2010) && (a >= 1608)) {
analogWrite(L1, 125);
} else if ((a < 2412) && (a >= 2010)) {
analogWrite(L1, 150);
} else if ((a < 2814) && (a >= 2412)) {
analogWrite(L1, 175);
} else if ((a < 3216) && (a >= 2814)) {
analogWrite(L1, 200);
} else if ((a < 3618) && (a >= 3216)) {
analogWrite(L1, 225);
} else if (a >= 3618) {
analogWrite(L1, 255);
}
}
if (b == 0) {
analogWrite(L2, 0);
} else {
if ((b < 402) && (b > 0)) {
analogWrite(L2, 25);
} else if ((b < 804) && (b >= 402)) {
analogWrite(L2, 50);
} else if ((b < 1206) && (b >= 804)) {
analogWrite(L2, 75);
} else if ((b < 1608) && (b >= 1206)) {
analogWrite(L2, 100);
} else if ((b < 2010) && (b >= 1608)) {
analogWrite(L2, 125);
} else if ((b < 2412) && (b >= 2010)) {
analogWrite(L2, 150);
} else if ((b < 2814) && (b >= 2412)) {
analogWrite(L2, 175);
} else if ((b < 3216) && (b >= 2814)) {
analogWrite(L2, 200);
} else if ((b < 3618) && (b >= 3216)) {
analogWrite(L2, 225);
} else if (b >= 3618) {
analogWrite(L2, 255);
}
}
if (c == 0) {
analogWrite(L3, 0);
} else {
if ((c < 402) && (c > 0)) {
analogWrite(L3, 25);
} else if ((c < 804) && (c >= 402)) {
analogWrite(L3, 50);
} else if ((c < 1206) && (c >= 804)) {
analogWrite(L3, 75);
} else if ((c < 1608) && (c >= 1206)) {
analogWrite(L3, 100);
} else if ((c < 2010) && (c >= 1608)) {
analogWrite(L3, 125);
} else if ((c < 2412) && (c >= 2010)) {
analogWrite(L3, 150);
} else if ((c < 2814) && (c >= 2412)) {
analogWrite(L3, 175);
} else if ((c < 3216) && (c >= 2814)) {
analogWrite(L3, 200);
} else if ((c < 3618) && (c >= 3216)) {
analogWrite(L3, 225);
} else if (c >= 3618) {
analogWrite(L3, 255);
}
}
if (d == 0) {
analogWrite(L4, 0);
} else {
if ((d < 402) && (d > 0)) {
analogWrite(L4, 25);
} else if ((d < 804) && (d >= 402)) {
analogWrite(L4, 50);
} else if ((d < 1206) && (d >= 804)) {
analogWrite(L4, 75);
} else if ((d < 1608) && (d >= 1206)) {
analogWrite(L4, 100);
} else if ((d < 2010) && (d >= 1608)) {
analogWrite(L4, 125);
} else if ((d < 2412) && (d >= 2010)) {
analogWrite(L4, 150);
} else if ((d < 2814) && (d >= 2412)) {
analogWrite(L4, 175);
} else if ((d < 3216) && (d >= 2814)) {
analogWrite(L4, 200);
} else if ((d < 3618) && (d >= 3216)) {
analogWrite(L4, 225);
} else if (d >= 3618) {
analogWrite(L4, 255);
}
}
}