Gerionte Team
/
BasculaDeCebo_B
Báscula de cebo funcionado.
main.cpp@2:11373e09c930, 2019-06-27 (annotated)
- Committer:
- bertonieto
- Date:
- Thu Jun 27 08:58:45 2019 +0000
- Revision:
- 2:11373e09c930
- Parent:
- 1:93d8becc35f9
Todo OK y funcionando
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oscarvzfz | 0:376d7a150177 | 1 | #include "mbed.h" |
oscarvzfz | 0:376d7a150177 | 2 | #include "TextLCD.h" |
bertonieto | 1:93d8becc35f9 | 3 | #include <string> |
bertonieto | 2:11373e09c930 | 4 | #include "MSCFileSystem.h" |
oscarvzfz | 0:376d7a150177 | 5 | |
bertonieto | 2:11373e09c930 | 6 | #define FSNAME "msc" |
bertonieto | 2:11373e09c930 | 7 | |
bertonieto | 2:11373e09c930 | 8 | MSCFileSystem msc(FSNAME); |
oscarvzfz | 0:376d7a150177 | 9 | |
bertonieto | 2:11373e09c930 | 10 | LocalFileSystem local("local"); |
bertonieto | 2:11373e09c930 | 11 | |
bertonieto | 2:11373e09c930 | 12 | int saleBicho; |
bertonieto | 2:11373e09c930 | 13 | //definimos la bascula para despues obtener el peso |
bertonieto | 1:93d8becc35f9 | 14 | Serial serialBascula(p9, p10); //Tx,Rx |
bertonieto | 1:93d8becc35f9 | 15 | |
bertonieto | 2:11373e09c930 | 16 | |
bertonieto | 2:11373e09c930 | 17 | //Definimos los LED |
bertonieto | 2:11373e09c930 | 18 | DigitalOut ledAux1(p15); |
bertonieto | 2:11373e09c930 | 19 | DigitalOut ledAux2(p29); |
bertonieto | 2:11373e09c930 | 20 | DigitalOut ledAux3(p30); |
bertonieto | 2:11373e09c930 | 21 | DigitalOut ledManual(p16); //Led de estado manual por defecto apagado |
bertonieto | 2:11373e09c930 | 22 | DigitalOut ledEntrada(p17); //Led de puerta de entrada por defecto apagado |
bertonieto | 2:11373e09c930 | 23 | DigitalOut ledSalida(p18); //Led de puerta de salida |
bertonieto | 2:11373e09c930 | 24 | DigitalOut ledIzquierda(p19); //Led de puerta Izquierda |
bertonieto | 2:11373e09c930 | 25 | DigitalOut ledDerecha(p20); //Led de puerta Derecha |
bertonieto | 2:11373e09c930 | 26 | |
bertonieto | 2:11373e09c930 | 27 | //Definimos las entradas |
bertonieto | 2:11373e09c930 | 28 | DigitalIn manual(p21); //Botón Manual |
bertonieto | 2:11373e09c930 | 29 | DigitalIn entrada(p5); //Botón Entrada |
bertonieto | 2:11373e09c930 | 30 | DigitalIn salida(p6); //Botón Salida |
bertonieto | 2:11373e09c930 | 31 | DigitalIn izquierda(p7); //Botón Izquierda |
bertonieto | 2:11373e09c930 | 32 | DigitalIn derecha(p8); //Botón Derecha |
bertonieto | 2:11373e09c930 | 33 | DigitalIn masMax(p22); //Botón Sumar Peso Max |
bertonieto | 2:11373e09c930 | 34 | DigitalIn menosMax(p23); //Botón Restar Peso Max |
bertonieto | 2:11373e09c930 | 35 | DigitalIn masMin(p24); //Botón Sumar Peso Min |
bertonieto | 2:11373e09c930 | 36 | DigitalIn menosMin(p25); //Botón Restar Peso Min |
bertonieto | 2:11373e09c930 | 37 | |
bertonieto | 2:11373e09c930 | 38 | DigitalIn sensorPiston(p26); //Sensor Piston |
bertonieto | 2:11373e09c930 | 39 | DigitalIn presenciaEntrada(p11); //Sensor Entrada |
bertonieto | 2:11373e09c930 | 40 | DigitalIn presenciaSalida(p12); //Sensor Salida |
bertonieto | 2:11373e09c930 | 41 | |
bertonieto | 2:11373e09c930 | 42 | //Escribimos en el USB |
bertonieto | 2:11373e09c930 | 43 | void escribirUSB(int peso) |
bertonieto | 2:11373e09c930 | 44 | { |
bertonieto | 2:11373e09c930 | 45 | FILE *fp = fopen( "/" FSNAME "/basculapesos.txt", "a"); |
bertonieto | 2:11373e09c930 | 46 | fprintf(fp, "%d \r\n", peso); |
bertonieto | 2:11373e09c930 | 47 | fclose(fp); |
bertonieto | 2:11373e09c930 | 48 | } |
bertonieto | 2:11373e09c930 | 49 | |
bertonieto | 2:11373e09c930 | 50 | //Iniciamos los led auxiliares. |
bertonieto | 2:11373e09c930 | 51 | void iniciaAux() |
bertonieto | 2:11373e09c930 | 52 | { |
bertonieto | 2:11373e09c930 | 53 | ledAux1 = 0; |
bertonieto | 2:11373e09c930 | 54 | ledAux2 = 0; |
bertonieto | 2:11373e09c930 | 55 | ledAux3 = 0; |
bertonieto | 2:11373e09c930 | 56 | } |
bertonieto | 2:11373e09c930 | 57 | //leemos de memoria flash la variable del peso minimo de clasificacion. |
bertonieto | 2:11373e09c930 | 58 | int leeMinMem() |
bertonieto | 2:11373e09c930 | 59 | { |
bertonieto | 2:11373e09c930 | 60 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
bertonieto | 2:11373e09c930 | 61 | FILE *fp = fopen("/local/MIN", "r"); // Open "out.txt" on the local file system for writing |
bertonieto | 2:11373e09c930 | 62 | char buffer [10]; |
bertonieto | 2:11373e09c930 | 63 | int minim; |
bertonieto | 2:11373e09c930 | 64 | fgets(buffer,10,fp); |
bertonieto | 2:11373e09c930 | 65 | fclose(fp); |
bertonieto | 2:11373e09c930 | 66 | minim=atoi(buffer); |
bertonieto | 2:11373e09c930 | 67 | return minim; |
bertonieto | 2:11373e09c930 | 68 | } |
bertonieto | 2:11373e09c930 | 69 | |
bertonieto | 2:11373e09c930 | 70 | //leemos de memoria flash la variable del peso maximo de clasificacion. |
bertonieto | 2:11373e09c930 | 71 | int leeMaxMem() |
bertonieto | 2:11373e09c930 | 72 | { |
bertonieto | 2:11373e09c930 | 73 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
bertonieto | 2:11373e09c930 | 74 | FILE *fp1 = fopen("/local/MAX", "r"); // Open "out.txt" on the local file system for writing |
bertonieto | 2:11373e09c930 | 75 | char buffer1 [10]; |
bertonieto | 2:11373e09c930 | 76 | int max; |
bertonieto | 2:11373e09c930 | 77 | fgets(buffer1,10,fp1); |
bertonieto | 2:11373e09c930 | 78 | fclose(fp1); |
bertonieto | 2:11373e09c930 | 79 | max=atoi(buffer1); |
bertonieto | 2:11373e09c930 | 80 | return max; |
bertonieto | 2:11373e09c930 | 81 | } |
bertonieto | 2:11373e09c930 | 82 | |
bertonieto | 2:11373e09c930 | 83 | //Iniciamos pesos Max y Min |
bertonieto | 2:11373e09c930 | 84 | int pesoMax = leeMaxMem(); |
bertonieto | 2:11373e09c930 | 85 | int pesoMin = leeMinMem(); |
bertonieto | 2:11373e09c930 | 86 | |
bertonieto | 2:11373e09c930 | 87 | |
bertonieto | 2:11373e09c930 | 88 | //Iniciamos I2C Communication |
bertonieto | 2:11373e09c930 | 89 | I2C i2c_lcd(p28,p27); // SDA, SCL |
bertonieto | 2:11373e09c930 | 90 | TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::HD44780); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type |
oscarvzfz | 0:376d7a150177 | 91 | |
bertonieto | 1:93d8becc35f9 | 92 | //Iniciamos el LCD. |
bertonieto | 2:11373e09c930 | 93 | void iniciaLCD() |
bertonieto | 2:11373e09c930 | 94 | { |
bertonieto | 1:93d8becc35f9 | 95 | lcd.setMode(TextLCD::DispOn); //DispOff, DispOn |
bertonieto | 1:93d8becc35f9 | 96 | lcd.setBacklight(TextLCD::LightOff);//LightOff, LightOn |
bertonieto | 1:93d8becc35f9 | 97 | lcd.setCursor(TextLCD::CurOff_BlkOff);//CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn |
bertonieto | 2:11373e09c930 | 98 | } |
bertonieto | 2:11373e09c930 | 99 | |
bertonieto | 2:11373e09c930 | 100 | //Pintamos en el LCD linea 1. |
bertonieto | 2:11373e09c930 | 101 | void pintaLCD1(bool manual){ |
bertonieto | 2:11373e09c930 | 102 | if (manual){ |
bertonieto | 2:11373e09c930 | 103 | lcd.locate(0,0); |
bertonieto | 2:11373e09c930 | 104 | lcd.printf(" MANUAL "); |
bertonieto | 2:11373e09c930 | 105 | } |
bertonieto | 2:11373e09c930 | 106 | else{ |
bertonieto | 2:11373e09c930 | 107 | lcd.locate(0,0); |
bertonieto | 2:11373e09c930 | 108 | lcd.printf("Salida1 Salida2"); |
bertonieto | 2:11373e09c930 | 109 | } |
bertonieto | 1:93d8becc35f9 | 110 | } |
bertonieto | 2:11373e09c930 | 111 | |
bertonieto | 2:11373e09c930 | 112 | //Pintamos en el LCD linea 2. |
bertonieto | 2:11373e09c930 | 113 | void pintaLCD2(){ |
bertonieto | 2:11373e09c930 | 114 | lcd.locate(0,1); |
bertonieto | 2:11373e09c930 | 115 | lcd.printf("<%dKg. ", pesoMin); |
bertonieto | 2:11373e09c930 | 116 | lcd.locate(7,1); |
bertonieto | 2:11373e09c930 | 117 | lcd.printf(" >%dKg.", pesoMax); |
bertonieto | 2:11373e09c930 | 118 | } |
oscarvzfz | 0:376d7a150177 | 119 | |
bertonieto | 1:93d8becc35f9 | 120 | int leerPeso(){ |
bertonieto | 2:11373e09c930 | 121 | char buffer1[30]; |
bertonieto | 2:11373e09c930 | 122 | string pesoss =""; |
bertonieto | 2:11373e09c930 | 123 | int ipesoss =0; |
bertonieto | 2:11373e09c930 | 124 | serialBascula.printf("2005002D:<CR><LF>\n"); //\r\n 2005002D:<CR><LF>\n |
bertonieto | 2:11373e09c930 | 125 | |
bertonieto | 2:11373e09c930 | 126 | pesoss = serialBascula.gets(buffer1,30); |
bertonieto | 2:11373e09c930 | 127 | if (buffer1[0]=='9'){ |
bertonieto | 2:11373e09c930 | 128 | pesoss = pesoss.substr(11,3); |
bertonieto | 2:11373e09c930 | 129 | ipesoss = atoi(pesoss.c_str()); |
bertonieto | 2:11373e09c930 | 130 | } |
bertonieto | 2:11373e09c930 | 131 | |
bertonieto | 2:11373e09c930 | 132 | return ipesoss; |
bertonieto | 2:11373e09c930 | 133 | } |
bertonieto | 2:11373e09c930 | 134 | |
bertonieto | 2:11373e09c930 | 135 | void escribeMaxMem(int i) |
bertonieto | 2:11373e09c930 | 136 | { |
bertonieto | 2:11373e09c930 | 137 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
bertonieto | 2:11373e09c930 | 138 | FILE *fp = fopen("/local/max", "w"); // Open "out.txt" on the local file system for writing |
bertonieto | 2:11373e09c930 | 139 | char buffer [10]; |
bertonieto | 2:11373e09c930 | 140 | sprintf (buffer, "%d", i); |
bertonieto | 2:11373e09c930 | 141 | fprintf(fp, buffer); |
bertonieto | 2:11373e09c930 | 142 | fclose(fp); |
bertonieto | 1:93d8becc35f9 | 143 | } |
bertonieto | 1:93d8becc35f9 | 144 | |
bertonieto | 2:11373e09c930 | 145 | void escribeMinMem(int i) |
bertonieto | 2:11373e09c930 | 146 | { |
bertonieto | 2:11373e09c930 | 147 | LocalFileSystem local("local"); // Create the local filesystem under the name "local" |
bertonieto | 2:11373e09c930 | 148 | FILE *fp = fopen("/local/min", "w"); // Open "out.txt" on the local file system for writing |
bertonieto | 2:11373e09c930 | 149 | char buffer [10]; |
bertonieto | 2:11373e09c930 | 150 | sprintf (buffer, "%d", i); |
bertonieto | 2:11373e09c930 | 151 | fprintf(fp, buffer); |
bertonieto | 2:11373e09c930 | 152 | fclose(fp); |
bertonieto | 2:11373e09c930 | 153 | } |
bertonieto | 2:11373e09c930 | 154 | |
bertonieto | 2:11373e09c930 | 155 | void cambioManual() |
bertonieto | 2:11373e09c930 | 156 | { |
bertonieto | 2:11373e09c930 | 157 | if (ledManual == 1){ |
bertonieto | 2:11373e09c930 | 158 | //reescribimos el dato en MAX y MIN al volver de manual por si se ha cambiado |
bertonieto | 2:11373e09c930 | 159 | escribeMaxMem(pesoMax); |
bertonieto | 2:11373e09c930 | 160 | escribeMinMem(pesoMin); |
bertonieto | 2:11373e09c930 | 161 | ledManual = 0; |
bertonieto | 2:11373e09c930 | 162 | pintaLCD1(0); |
bertonieto | 2:11373e09c930 | 163 | wait(0.50); |
bertonieto | 2:11373e09c930 | 164 | } |
bertonieto | 2:11373e09c930 | 165 | else{ |
bertonieto | 2:11373e09c930 | 166 | ledManual = 1; |
bertonieto | 2:11373e09c930 | 167 | pintaLCD1(1); |
bertonieto | 2:11373e09c930 | 168 | wait(0.50); |
bertonieto | 2:11373e09c930 | 169 | } |
bertonieto | 2:11373e09c930 | 170 | } |
bertonieto | 2:11373e09c930 | 171 | |
bertonieto | 2:11373e09c930 | 172 | |
bertonieto | 1:93d8becc35f9 | 173 | //Main, aqui ponemos todo el programa. |
bertonieto | 2:11373e09c930 | 174 | int main() |
bertonieto | 2:11373e09c930 | 175 | { |
bertonieto | 2:11373e09c930 | 176 | Serial pc(USBTX, USBRX); |
bertonieto | 1:93d8becc35f9 | 177 | iniciaLCD(); //Iniciamos el LCD |
bertonieto | 2:11373e09c930 | 178 | pintaLCD1(0); |
bertonieto | 2:11373e09c930 | 179 | pintaLCD2(); |
bertonieto | 1:93d8becc35f9 | 180 | int pesoreal; |
bertonieto | 2:11373e09c930 | 181 | //int estaPesado; //si esta pesado 1, si no esta pesado 0 |
bertonieto | 1:93d8becc35f9 | 182 | |
bertonieto | 2:11373e09c930 | 183 | while(1) { |
bertonieto | 2:11373e09c930 | 184 | //Modo manual: se pueden cambiar pesos y mover las puertas |
bertonieto | 2:11373e09c930 | 185 | while(ledManual == 1) |
bertonieto | 2:11373e09c930 | 186 | { |
bertonieto | 2:11373e09c930 | 187 | if (manual == 1) |
bertonieto | 2:11373e09c930 | 188 | { |
bertonieto | 2:11373e09c930 | 189 | cambioManual();} |
bertonieto | 2:11373e09c930 | 190 | if (entrada == 1) |
bertonieto | 2:11373e09c930 | 191 | { |
bertonieto | 2:11373e09c930 | 192 | if(ledEntrada == 1) |
bertonieto | 2:11373e09c930 | 193 | { |
bertonieto | 2:11373e09c930 | 194 | ledEntrada = 0; |
bertonieto | 2:11373e09c930 | 195 | wait(0.50); |
bertonieto | 2:11373e09c930 | 196 | } |
bertonieto | 2:11373e09c930 | 197 | else |
bertonieto | 2:11373e09c930 | 198 | { |
bertonieto | 2:11373e09c930 | 199 | ledEntrada = 1; |
bertonieto | 2:11373e09c930 | 200 | wait(0.50); |
bertonieto | 2:11373e09c930 | 201 | } |
bertonieto | 2:11373e09c930 | 202 | } |
bertonieto | 2:11373e09c930 | 203 | if (salida == 1) |
bertonieto | 2:11373e09c930 | 204 | { |
bertonieto | 2:11373e09c930 | 205 | if(ledSalida == 1) |
bertonieto | 2:11373e09c930 | 206 | { |
bertonieto | 2:11373e09c930 | 207 | ledSalida = 0; |
bertonieto | 2:11373e09c930 | 208 | wait(0.50); |
bertonieto | 2:11373e09c930 | 209 | } |
bertonieto | 2:11373e09c930 | 210 | else |
bertonieto | 2:11373e09c930 | 211 | { |
bertonieto | 2:11373e09c930 | 212 | ledSalida = 1; |
bertonieto | 2:11373e09c930 | 213 | wait(0.50); |
bertonieto | 2:11373e09c930 | 214 | } |
bertonieto | 2:11373e09c930 | 215 | } |
bertonieto | 2:11373e09c930 | 216 | if (izquierda == 1) |
bertonieto | 2:11373e09c930 | 217 | { |
bertonieto | 2:11373e09c930 | 218 | ledIzquierda = 1; |
bertonieto | 2:11373e09c930 | 219 | wait(0.50); |
bertonieto | 2:11373e09c930 | 220 | ledIzquierda = 0; |
bertonieto | 2:11373e09c930 | 221 | } |
bertonieto | 2:11373e09c930 | 222 | if (derecha == 1) |
bertonieto | 2:11373e09c930 | 223 | { |
bertonieto | 2:11373e09c930 | 224 | if(ledDerecha == 1) |
bertonieto | 2:11373e09c930 | 225 | { |
bertonieto | 2:11373e09c930 | 226 | ledDerecha = 0; |
bertonieto | 2:11373e09c930 | 227 | wait(0.50); |
bertonieto | 2:11373e09c930 | 228 | } |
bertonieto | 2:11373e09c930 | 229 | else |
bertonieto | 2:11373e09c930 | 230 | { |
bertonieto | 2:11373e09c930 | 231 | ledDerecha = 1; |
bertonieto | 2:11373e09c930 | 232 | wait(0.50); |
bertonieto | 2:11373e09c930 | 233 | } |
bertonieto | 2:11373e09c930 | 234 | } |
bertonieto | 2:11373e09c930 | 235 | if (masMax == 1) |
bertonieto | 2:11373e09c930 | 236 | { |
bertonieto | 2:11373e09c930 | 237 | if (pesoMax < 2000) |
bertonieto | 2:11373e09c930 | 238 | { |
bertonieto | 2:11373e09c930 | 239 | pesoMax += 1; |
bertonieto | 2:11373e09c930 | 240 | wait(0.10); |
bertonieto | 2:11373e09c930 | 241 | pintaLCD2(); |
bertonieto | 2:11373e09c930 | 242 | } |
bertonieto | 2:11373e09c930 | 243 | } |
bertonieto | 2:11373e09c930 | 244 | if (menosMax == 1) |
bertonieto | 2:11373e09c930 | 245 | { |
bertonieto | 2:11373e09c930 | 246 | if (pesoMax > (pesoMin + 1)) |
bertonieto | 2:11373e09c930 | 247 | { |
bertonieto | 2:11373e09c930 | 248 | pesoMax -= 1; |
bertonieto | 2:11373e09c930 | 249 | wait(0.10); |
bertonieto | 2:11373e09c930 | 250 | pintaLCD2(); |
bertonieto | 2:11373e09c930 | 251 | } |
bertonieto | 2:11373e09c930 | 252 | } |
bertonieto | 2:11373e09c930 | 253 | if (masMin == 1) |
bertonieto | 2:11373e09c930 | 254 | { |
bertonieto | 2:11373e09c930 | 255 | if(pesoMin < (pesoMax - 1)) |
bertonieto | 2:11373e09c930 | 256 | { |
bertonieto | 2:11373e09c930 | 257 | pesoMin += 1; |
bertonieto | 2:11373e09c930 | 258 | wait(0.10); |
bertonieto | 2:11373e09c930 | 259 | pintaLCD2(); |
bertonieto | 2:11373e09c930 | 260 | } |
bertonieto | 2:11373e09c930 | 261 | } |
bertonieto | 2:11373e09c930 | 262 | if (menosMin == 1) |
bertonieto | 2:11373e09c930 | 263 | {if(pesoMin > 10) |
bertonieto | 2:11373e09c930 | 264 | { |
bertonieto | 2:11373e09c930 | 265 | pesoMin -= 1; |
bertonieto | 2:11373e09c930 | 266 | wait(0.10); |
bertonieto | 2:11373e09c930 | 267 | pintaLCD2(); |
bertonieto | 2:11373e09c930 | 268 | } |
bertonieto | 2:11373e09c930 | 269 | } |
bertonieto | 1:93d8becc35f9 | 270 | } |
bertonieto | 2:11373e09c930 | 271 | //empezamos el programa |
bertonieto | 2:11373e09c930 | 272 | ledEntrada = 1; |
bertonieto | 2:11373e09c930 | 273 | ledSalida = 1; |
bertonieto | 2:11373e09c930 | 274 | ledDerecha = 0; |
bertonieto | 2:11373e09c930 | 275 | ledIzquierda = 0; |
bertonieto | 2:11373e09c930 | 276 | pesoreal = 0; |
bertonieto | 2:11373e09c930 | 277 | saleBicho = 0; |
bertonieto | 2:11373e09c930 | 278 | if (manual == 1){ |
bertonieto | 2:11373e09c930 | 279 | cambioManual(); |
bertonieto | 2:11373e09c930 | 280 | } |
bertonieto | 2:11373e09c930 | 281 | |
bertonieto | 2:11373e09c930 | 282 | //Bucle de entrada a la báscula y funcionamiento real |
bertonieto | 2:11373e09c930 | 283 | wait(0.2); |
bertonieto | 2:11373e09c930 | 284 | int tiempoSinSensorPiston = 0; |
bertonieto | 2:11373e09c930 | 285 | while(presenciaEntrada == 1 && ledManual == 0){ |
bertonieto | 2:11373e09c930 | 286 | ledEntrada = 0; |
bertonieto | 2:11373e09c930 | 287 | //Se Comprueba que el bicho no ha salido para no mover la puerta de salida |
bertonieto | 2:11373e09c930 | 288 | if (saleBicho == 0){ |
bertonieto | 2:11373e09c930 | 289 | ledSalida = 0; |
bertonieto | 2:11373e09c930 | 290 | } |
bertonieto | 2:11373e09c930 | 291 | //Se comprueba que no se cambia a manual |
bertonieto | 2:11373e09c930 | 292 | if (manual == 1){cambioManual();} |
bertonieto | 2:11373e09c930 | 293 | wait(1); |
bertonieto | 2:11373e09c930 | 294 | if(sensorPiston == 1){ |
bertonieto | 2:11373e09c930 | 295 | //Tiempo a esperar para que la bascula calcule el liveWeitgh |
bertonieto | 2:11373e09c930 | 296 | int tiempoLectura = 0; |
bertonieto | 2:11373e09c930 | 297 | //Bucle de espera para obtener el peso (3,5 s) |
bertonieto | 2:11373e09c930 | 298 | while(tiempoLectura < 40 && ledManual == 0 && presenciaEntrada == 1){ |
bertonieto | 2:11373e09c930 | 299 | wait(0.1); |
bertonieto | 2:11373e09c930 | 300 | if (manual == 1){cambioManual();} |
bertonieto | 2:11373e09c930 | 301 | tiempoLectura++; |
bertonieto | 2:11373e09c930 | 302 | } |
bertonieto | 2:11373e09c930 | 303 | if (saleBicho == 0){ |
bertonieto | 2:11373e09c930 | 304 | pesoreal = leerPeso(); |
bertonieto | 2:11373e09c930 | 305 | //estaPesado = 1; |
bertonieto | 2:11373e09c930 | 306 | wait(0.8); |
bertonieto | 2:11373e09c930 | 307 | } |
bertonieto | 2:11373e09c930 | 308 | //Comprobamos el pero obtenido para clasificar o salir |
bertonieto | 2:11373e09c930 | 309 | if (pesoreal < 50000 && ledManual == 0 && presenciaEntrada == 1){ |
bertonieto | 2:11373e09c930 | 310 | if (pesoreal > pesoMin && saleBicho == 0){ |
bertonieto | 2:11373e09c930 | 311 | ledDerecha = 1; |
bertonieto | 2:11373e09c930 | 312 | //escribimos el peso real en el USB |
bertonieto | 2:11373e09c930 | 313 | //escribirUSB(pesoreal); |
bertonieto | 2:11373e09c930 | 314 | if (pesoreal < pesoMax){ |
bertonieto | 2:11373e09c930 | 315 | ledIzquierda = 1; |
bertonieto | 2:11373e09c930 | 316 | wait(0.5); |
bertonieto | 2:11373e09c930 | 317 | ledIzquierda = 0; |
bertonieto | 2:11373e09c930 | 318 | } |
bertonieto | 2:11373e09c930 | 319 | wait(0.50); |
bertonieto | 2:11373e09c930 | 320 | } |
bertonieto | 2:11373e09c930 | 321 | wait(0.1); |
bertonieto | 2:11373e09c930 | 322 | if(ledManual == 0){ |
bertonieto | 2:11373e09c930 | 323 | ledSalida = 1; |
bertonieto | 2:11373e09c930 | 324 | } |
bertonieto | 2:11373e09c930 | 325 | saleBicho = 1; |
bertonieto | 2:11373e09c930 | 326 | } |
bertonieto | 2:11373e09c930 | 327 | } |
bertonieto | 2:11373e09c930 | 328 | //Else del if del sensor del piston |
bertonieto | 2:11373e09c930 | 329 | else{ |
bertonieto | 2:11373e09c930 | 330 | tiempoSinSensorPiston = tiempoSinSensorPiston +1; |
bertonieto | 2:11373e09c930 | 331 | wait(0.5); |
bertonieto | 2:11373e09c930 | 332 | if (tiempoSinSensorPiston > 10){ |
bertonieto | 2:11373e09c930 | 333 | ledEntrada = 1; |
bertonieto | 2:11373e09c930 | 334 | wait(2); |
bertonieto | 2:11373e09c930 | 335 | } |
bertonieto | 2:11373e09c930 | 336 | } |
bertonieto | 2:11373e09c930 | 337 | } |
bertonieto | 2:11373e09c930 | 338 | } |
bertonieto | 2:11373e09c930 | 339 | } |