Skip to content

Commit 94ba200

Browse files
committed
Guardar
1 parent cdbc36c commit 94ba200

31 files changed

+508
-277
lines changed

include/Config.h

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct Variables_config
2020
const uint8_t HX711_dout{A1};
2121
const uint8_t HX711_sck{A0};
2222
const short calVal_eepromAdress{0};
23-
const short Num_elementos{8};
2423
const float densidad{1000};
2524
};
2625

include/Manejo_datos.h

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MANEJO_DATOS_H
33

44
#include <Memoria_no_volatil.h>
5+
#include "Config.h"
56

67
namespace Manejo_datos
78
{

lib/Caudal/Caudal.cpp

+208-41
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,73 @@
11
#include "Caudal.h"
22

3-
//Configuraciones:
3+
// Configuraciones:
44
static Variables_config config;
5-
//instanciado la celda de carga.
5+
// instanciado la celda de carga.
66
HX711 Caudal::balanza;
7+
// Instanciado Pantalla:
8+
static LiquidCrystal LCD(7, 6, 5, 4, 3, 2);
79

8-
//Constructor:
10+
// Constructor:
911
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)
1113
{
1214
this->caudal = 0;
1315
this->tiempo = millis();
1416
this->tanq_altura = 0;
1517
this->advertencia = false;
1618
this->Peso_ultimo = 0;
19+
this->peso_turno = 0;
20+
LCD.begin(16, 2);
21+
this->nivel = '0';
22+
this->confirmacion=false;
1723
}
1824

19-
//Calculo del volumen.
25+
// Calculo del volumen.
2026
float Caudal::volumen(float &peso)
2127
{
2228
return (densidad * peso) / GRAVEDAD;
2329
}
2430

25-
//Inicializa la celdad de carga.
31+
// Inicializa la celdad de carga.
2632
void Caudal::set_valores(float valores[3], float &altura)
2733
{
2834
this->valores = &valores[0];
2935
this->tanq_altura = altura;
30-
//Obtener valores de la EEPROM
31-
//Serial.println("Starting...");
3236
balanza.begin(config.HX711_dout, config.HX711_sck);
3337
Serial.println(balanza.read());
3438
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);
3645
}
3746

38-
//Muestra si el tanque se está vaceando o no.
47+
// Muestra si el tanque se está vaceando o no.
3948
int Caudal::estado(float &peso)
4049
{
50+
if ((Peso_ultimo - 0.3) > peso)
51+
{
52+
Peso_ultimo += Peso_ultimo;
53+
}
4154
Peso_ultimo = Peso_ultimo < peso ? peso : Peso_ultimo;
4255
return (Peso_ultimo - 0.2) < peso ? 1 : -1;
4356
}
4457

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()
4760
{
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+
/*
5471
switch (estado(peso))
5572
{
5673
case -1:
@@ -64,17 +81,18 @@ bool& Caudal::Valores()
6481
Serial.println("Error: Inestable.");
6582
break;
6683
}
84+
*/
6785
return advertencia;
6886
}
6987

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)
7290
{
7391
return caudal / value_caudal <= 0.1 ? true : false;
7492
}
7593

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()
7896
{
7997
int valor{0};
8098
unsigned long time{0};
@@ -84,71 +102,220 @@ float& Caudal::delta_caudal()
84102
// Realizar derivada:
85103
do
86104
{
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);
90108
caudal /= (tiempo - time);
91109
continua = false;
92110
}
93111
time = millis();
94112
valor = Cal_peso();
95-
}
96-
while (continua);
113+
delay(100);
114+
} while (continua);
97115
// Imprimir derivada:
98116
Serial.println(caudal);
99117
// Retorna el resultado:
100118
return caudal;
101119
}
102120

103-
//Cálculo de la altura en función del peso.
121+
// Cálculo de la altura en función del peso.
104122
float Caudal::altura(float &peso)
105123
{
106-
if(valores != nullptr)
124+
if (valores != nullptr)
107125
{
108-
return (valores[0]*(peso)*(peso)) + valores[1]*peso + valores[0];
126+
return (valores[2] * (peso) * (peso)) + valores[1] * peso + valores[0];
109127
}
110128
return -1;
111129
}
112130

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.
114132
bool Caudal::variacion_altura(float altura, float porcentaje)
115133
{
116-
return ((altura/tanq_altura) * 100)/porcentaje < 0.2 ? true: false;
134+
return ((altura / tanq_altura) * 100) / porcentaje < 0.2 ? true : false;
117135
}
118136

119-
//Toma de valores de la celadad de carga.
137+
// Toma de valores de la celadad de carga.
120138
float Caudal::Cal_peso()
121139
{
122140
Serial.print(balanza.get_units(20), 3);
123141
delay(500);
124142
return balanza.get_units(20);
125143
}
126144

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)
129147
{
130148
if (offset == 0)
131149
{
132150
balanza.begin(config.HX711_dout, config.HX711_sck);
133-
Serial.println(balanza.read());
151+
// balanza.read();
134152
balanza.set_scale(); // La escala por defecto es 1
135153
balanza.tare(20); // El peso actual es considerado Tara.
136154
offset = balanza.get_offset();
137155
}
138156
else
139157
{
140-
if(realizar)
158+
if (realizar)
141159
{
142-
float array[10] = {};
160+
sum = 0;
161+
Variables::Lcd.clear();
162+
Variables::Lcd.setCursor(0, 0);
163+
Variables::Lcd.print("Tomando");
143164
for (short i = 0; i < 10; i++)
144165
{
145-
array[i % 10] = balanza.get_value(10);
146-
sum += array[i % 10];
166+
sum += balanza.get_value(10);
147167
delay(100);
148168
}
169+
sum /= 10;
149170
return true;
150171
}
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);
152176
}
153177
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");
154321
}

0 commit comments

Comments
 (0)