1
1
#include " Caudal.h"
2
2
3
- // Configuraciones:
3
+ // Configuraciones:
4
4
static Variables_config config;
5
- // instanciado la celda de carga.
5
+ // instanciado la celda de carga.
6
6
HX711 Caudal::balanza;
7
+ // Instanciado Pantalla:
8
+ static LiquidCrystal LCD (7 , 6 , 5 , 4 , 3 , 2 );
7
9
8
- // Constructor:
10
+ // Constructor:
9
11
Caudal::Caudal (const float &densidad, const float &peso, Variables_Guardar &variables, const float &teoric_caudal) :
10
- densidad(densidad), valores(nullptr ), Peso_total(peso), value_caudal(teoric_caudal), variables(variables)
12
+ densidad(densidad), valores(nullptr ), Peso_total(peso), value_caudal(teoric_caudal), variables(variables), LCD( 7 , 6 , 5 , 4 , 3 , 2 )
11
13
{
12
14
this ->caudal = 0 ;
13
15
this ->tiempo = millis ();
14
16
this ->tanq_altura = 0 ;
15
17
this ->advertencia = false ;
16
18
this ->Peso_ultimo = 0 ;
19
+ this ->peso_turno = 0 ;
20
+ LCD.begin (16 , 2 );
21
+ this ->nivel = ' 0' ;
22
+ this ->confirmacion =false ;
17
23
}
18
24
19
- // Calculo del volumen.
25
+ // Calculo del volumen.
20
26
float Caudal::volumen (float &peso)
21
27
{
22
28
return (densidad * peso) / GRAVEDAD;
23
29
}
24
30
25
- // Inicializa la celdad de carga.
31
+ // Inicializa la celdad de carga.
26
32
void Caudal::set_valores (float valores[3 ], float &altura)
27
33
{
28
34
this ->valores = &valores[0 ];
29
35
this ->tanq_altura = altura;
30
- // Obtener valores de la EEPROM
31
- // Serial.println("Starting...");
32
36
balanza.begin (config.HX711_dout , config.HX711_sck );
33
37
Serial.println (balanza.read ());
34
38
balanza.set_scale (variables.suma_valores ); // Establecemos la escala
35
- balanza.set_offset (variables.t ); // El peso actual es considerado Tara.
39
+ balanza.set_offset (variables.t ); // El peso actual es considerado Tara.
40
+ pinMode (Sensor20, INPUT);
41
+ pinMode (Sensor40, INPUT);
42
+ pinMode (Sensor60, INPUT);
43
+ pinMode (Sensor80, INPUT);
44
+ pinMode (Sensor100, INPUT);
36
45
}
37
46
38
- // Muestra si el tanque se está vaceando o no.
47
+ // Muestra si el tanque se está vaceando o no.
39
48
int Caudal::estado (float &peso)
40
49
{
50
+ if ((Peso_ultimo - 0.3 ) > peso)
51
+ {
52
+ Peso_ultimo += Peso_ultimo;
53
+ }
41
54
Peso_ultimo = Peso_ultimo < peso ? peso : Peso_ultimo;
42
55
return (Peso_ultimo - 0.2 ) < peso ? 1 : -1 ;
43
56
}
44
57
45
- // Muestre el volumen y el porcentaje del taque lleno.
46
- bool & Caudal::Valores ()
58
+ // Muestre el volumen y el porcentaje del taque lleno.
59
+ bool & Caudal::Valores ()
47
60
{
48
- float peso = delta_caudal ();
49
- peso = peso >= 0 ? peso : 0 ;
50
- Serial.print (" Volumen: " );
51
- Serial.print (volumen (peso));
52
- Serial.print (" %Llenado: " );
53
- Serial.println ((altura (peso) / tanq_altura) * 100 );
61
+ // float peso = delta_caudal();
62
+ // peso = peso >= 0 ? peso : 0;
63
+ // float nivel = (altura(peso) / tanq_altura) * 100;
64
+ LCD.setCursor (0 , 0 );
65
+ String aux = " V: " + String (1.2456 /* volumen(peso)*/ , 2 ) + " C: " + String (2.345 /* peso, 3*/ , 2 );
66
+ LCD.print (aux);
67
+ LCD.setCursor (0 , 1 );
68
+ String aux2 = " N: " + String (2 /* nivel, 3*/ ) + " % " + " T: " + String (10 ) + " l" ;
69
+ LCD.print (aux2);
70
+ /*
54
71
switch (estado(peso))
55
72
{
56
73
case -1:
@@ -64,17 +81,18 @@ bool& Caudal::Valores()
64
81
Serial.println("Error: Inestable.");
65
82
break;
66
83
}
84
+ */
67
85
return advertencia;
68
86
}
69
87
70
- // Variación del caudal de vaceado cuando se da apertura a la valvula manual.
71
- bool Caudal::variacion_peso (float & caudal)
88
+ // Variación del caudal de vaceado cuando se da apertura a la valvula manual.
89
+ bool Caudal::variacion_peso (float & caudal)
72
90
{
73
91
return caudal / value_caudal <= 0.1 ? true : false ;
74
92
}
75
93
76
- // Derivada de la señal de peso.
77
- float & Caudal::delta_caudal ()
94
+ // Derivada de la señal de peso.
95
+ float & Caudal::delta_caudal ()
78
96
{
79
97
int valor{0 };
80
98
unsigned long time {0 };
@@ -84,71 +102,220 @@ float& Caudal::delta_caudal()
84
102
// Realizar derivada:
85
103
do
86
104
{
87
- if (time != tiempo && time != 0 && valor != 0 )
88
- {
89
- caudal = (valor- out);
105
+ if (time != tiempo && time != 0 && valor != 0 )
106
+ {
107
+ caudal = (valor - out);
90
108
caudal /= (tiempo - time );
91
109
continua = false ;
92
110
}
93
111
time = millis ();
94
112
valor = Cal_peso ();
95
- }
96
- while (continua);
113
+ delay ( 100 );
114
+ } while (continua);
97
115
// Imprimir derivada:
98
116
Serial.println (caudal);
99
117
// Retorna el resultado:
100
118
return caudal;
101
119
}
102
120
103
- // Cálculo de la altura en función del peso.
121
+ // Cálculo de la altura en función del peso.
104
122
float Caudal::altura (float &peso)
105
123
{
106
- if (valores != nullptr )
124
+ if (valores != nullptr )
107
125
{
108
- return (valores[0 ]* (peso)* (peso)) + valores[1 ]* peso + valores[0 ];
126
+ return (valores[2 ] * (peso) * (peso)) + valores[1 ] * peso + valores[0 ];
109
127
}
110
128
return -1 ;
111
129
}
112
130
113
- // Cálculo de la variación de la altura en función del valor teorico.
131
+ // Cálculo de la variación de la altura en función del valor teorico.
114
132
bool Caudal::variacion_altura (float altura, float porcentaje)
115
133
{
116
- return ((altura/ tanq_altura) * 100 )/ porcentaje < 0.2 ? true : false ;
134
+ return ((altura / tanq_altura) * 100 ) / porcentaje < 0.2 ? true : false ;
117
135
}
118
136
119
- // Toma de valores de la celadad de carga.
137
+ // Toma de valores de la celadad de carga.
120
138
float Caudal::Cal_peso ()
121
139
{
122
140
Serial.print (balanza.get_units (20 ), 3 );
123
141
delay (500 );
124
142
return balanza.get_units (20 );
125
143
}
126
144
127
- // Configura los valores inciales para calibrar la celdad de carga.
128
- bool Caudal::calibracion_escala (long &offset, float &sum, bool & realizar)
145
+ // Configura los valores inciales para calibrar la celdad de carga.
146
+ bool Caudal::calibracion_escala (long &offset, float &sum, bool & realizar)
129
147
{
130
148
if (offset == 0 )
131
149
{
132
150
balanza.begin (config.HX711_dout , config.HX711_sck );
133
- Serial. println ( balanza.read () );
151
+ // balanza.read();
134
152
balanza.set_scale (); // La escala por defecto es 1
135
153
balanza.tare (20 ); // El peso actual es considerado Tara.
136
154
offset = balanza.get_offset ();
137
155
}
138
156
else
139
157
{
140
- if (realizar)
158
+ if (realizar)
141
159
{
142
- float array[10 ] = {};
160
+ sum = 0 ;
161
+ Variables::Lcd.clear ();
162
+ Variables::Lcd.setCursor (0 , 0 );
163
+ Variables::Lcd.print (" Tomando" );
143
164
for (short i = 0 ; i < 10 ; i++)
144
165
{
145
- array[i % 10 ] = balanza.get_value (10 );
146
- sum += array[i % 10 ];
166
+ sum += balanza.get_value (10 );
147
167
delay (100 );
148
168
}
169
+ sum /= 10 ;
149
170
return true ;
150
171
}
151
- Serial.println (balanza.get_value (10 ));
172
+ Variables::Lcd.setCursor (0 , 0 );
173
+ Variables::Lcd.print (" Valor: " );
174
+ Variables::Lcd.print (balanza.get_value (10 ));
175
+ delay (100 );
152
176
}
153
177
return false ;
178
+ }
179
+
180
+ int Caudal::lectura_values ()
181
+ {
182
+ if (digitalRead (Sensor20) == LOW && digitalRead (Sensor40) == HIGH && nivel != ' 1' )
183
+ {
184
+ if (confirmacion)
185
+ {
186
+ nivel = ' 1' ;
187
+ confirmacion = false ;
188
+ return 1 ;
189
+ }
190
+ else
191
+ {
192
+ confirmacion = false ;
193
+ delay (500 );
194
+ }
195
+ }
196
+ else if (digitalRead (Sensor40) == LOW && digitalRead (Sensor60) == HIGH && nivel != ' 2' )
197
+ {
198
+ if (confirmacion)
199
+ {
200
+ nivel = ' 2' ;
201
+ confirmacion = false ;
202
+ return 2 ;
203
+ }
204
+ else
205
+ {
206
+ confirmacion = false ;
207
+ delay (500 );
208
+ }
209
+ }
210
+ else if (digitalRead (Sensor60) == LOW && digitalRead (Sensor80) == HIGH && nivel != ' 3' )
211
+ {
212
+ if (confirmacion)
213
+ {
214
+ nivel = ' 3' ;
215
+ confirmacion = false ;
216
+ return 3 ;
217
+ }
218
+ else
219
+ {
220
+ confirmacion = false ;
221
+ delay (500 );
222
+ }
223
+ }
224
+ else if (digitalRead (Sensor80) == LOW && digitalRead (Sensor100) == HIGH && nivel != ' 4' )
225
+ {
226
+ if (confirmacion)
227
+ {
228
+ nivel = ' 4' ;
229
+ confirmacion = false ;
230
+ return 4 ;
231
+ }
232
+ else
233
+ {
234
+ confirmacion = true ;
235
+ delay (500 );
236
+ }
237
+ }
238
+ else if (digitalRead (Sensor100) == LOW && digitalRead (Sensor80) == HIGH && nivel != ' 5' )
239
+ {
240
+ if (confirmacion)
241
+ {
242
+ nivel = ' 5' ;
243
+ confirmacion = false ;
244
+ return 5 ;
245
+ }
246
+ else
247
+ {
248
+ confirmacion = true ;
249
+ delay (500 );
250
+ }
251
+ }
252
+ else
253
+ {
254
+ confirmacion = false ;
255
+ }
256
+ return 0 ;
257
+ }
258
+
259
+ char Caudal::return_value_nivel ()
260
+ {
261
+ return nivel;
262
+ }
263
+
264
+ void Caudal::Calibracion_niveles (float array[5 ])
265
+ {
266
+ bool continuar{true };
267
+ LCD.setCursor (0 , 0 );
268
+ LCD.print (" Peso: " );
269
+ LCD.print (Cal_peso ());
270
+ while (continuar)
271
+ {
272
+ while (lectura_values () > 0 )
273
+ switch (nivel)
274
+ {
275
+ case ' 1' :
276
+ LCD.clear ();
277
+ LCD.setCursor (0 , 0 );
278
+ LCD.print (" #1 tomado" );
279
+ array[0 ] = Cal_peso ();
280
+ delay (1000 );
281
+ LCD.clear ();
282
+ break ;
283
+ case ' 2' :
284
+ LCD.clear ();
285
+ LCD.setCursor (0 , 0 );
286
+ LCD.print (" #2 tomado" );
287
+ array[1 ] = Cal_peso ();
288
+ delay (1000 );
289
+ LCD.clear ();
290
+ break ;
291
+ case ' 3' :
292
+ LCD.clear ();
293
+ LCD.setCursor (0 , 0 );
294
+ LCD.print (" #3 tomado" );
295
+ array[2 ] = Cal_peso ();
296
+ delay (1000 );
297
+ LCD.clear ();
298
+ break ;
299
+ case ' 4' :
300
+ break ;
301
+ LCD.clear ();
302
+ LCD.setCursor (0 , 0 );
303
+ LCD.print (" #4 tomado" );
304
+ array[3 ] = Cal_peso ();
305
+ delay (1000 );
306
+ LCD.clear ();
307
+ case ' 5' :
308
+ LCD.clear ();
309
+ LCD.setCursor (0 , 0 );
310
+ array[4 ] = Cal_peso ();
311
+ LCD.clear ();
312
+ continuar = false ;
313
+ break ;
314
+ default :
315
+ break ;
316
+ }
317
+ }
318
+ LCD.clear ();
319
+ LCD.setCursor (0 ,0 );
320
+ LCD.print (" Medidas Tomadas" );
154
321
}
0 commit comments