Alarma de pico y placa usando módulo RTC.

Dependencies:   QEI TextLCD mbed

Fork of grafica_PID_android by Nicolás Villegas Echavarría

Committer:
NicolasV
Date:
Sat Jun 03 01:10:48 2017 +0000
Revision:
4:d57cde44861e
Parent:
3:2e823b16a4a1
Alarma de pico y placa;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NicolasV 2:00db719ebd81 1 /*
NicolasV 2:00db719ebd81 2 * Código por: Laura Álvila
NicolasV 2:00db719ebd81 3 * Daniela López
NicolasV 2:00db719ebd81 4 * Nicolás Villegas
NicolasV 2:00db719ebd81 5 */
NicolasV 2:00db719ebd81 6
tony63 0:4e0dfcf0e7ce 7 #include "mbed.h"
tony63 0:4e0dfcf0e7ce 8 #include "QEI.h"
tony63 0:4e0dfcf0e7ce 9 #include "TextLCD.h"
NicolasV 4:d57cde44861e 10 #include "Rtc_Ds1307.h"
tony63 0:4e0dfcf0e7ce 11
NicolasV 4:d57cde44861e 12 Rtc_Ds1307 rtc(PTC9, PTC8);
NicolasV 2:00db719ebd81 13 Serial GSM(PTE0,PTE1); // Módulo Bluetooh
tony63 0:4e0dfcf0e7ce 14 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
NicolasV 4:d57cde44861e 15 QEI encoder (PTA13, PTD5, NC, 300);
NicolasV 4:d57cde44861e 16 DigitalOut alarma(PTA5);
NicolasV 4:d57cde44861e 17 DigitalOut carro(PTA4);
NicolasV 4:d57cde44861e 18 DigitalOut led2(LED2);
NicolasV 3:2e823b16a4a1 19 Timer t;
NicolasV 2:00db719ebd81 20
NicolasV 2:00db719ebd81 21 AnalogIn y(PTC2); // Entrada análoga: Salida del sistema
NicolasV 2:00db719ebd81 22 AnalogOut u(PTE30); // Salida análoga: Señal de control
NicolasV 2:00db719ebd81 23
NicolasV 2:00db719ebd81 24 DigitalIn button3(PTC16); // Botón del encoder
NicolasV 2:00db719ebd81 25 DigitalIn button4(PTC17); // Pulsador
tony63 0:4e0dfcf0e7ce 26
NicolasV 2:00db719ebd81 27 // Códigos movimiento del cursor:
NicolasV 4:d57cde44861e 28 const int C1 = 0x0F; // Habilitar cursor
NicolasV 4:d57cde44861e 29 const int C2 = 0x18; // Desplazar pantalla izq.
NicolasV 4:d57cde44861e 30 const int C4 = 0x0C; // Quitar cursor
NicolasV 4:d57cde44861e 31
NicolasV 4:d57cde44861e 32 const char abc[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; // Abecedario para seleccionar la placa.
NicolasV 4:d57cde44861e 33 char* dias[] = {"Dia", "Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab"}; // Dias de la semana para la configuración del reloj.
NicolasV 4:d57cde44861e 34 int p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0, p6 = 0; // 6 dígitos de la placa.
tony63 0:4e0dfcf0e7ce 35
NicolasV 4:d57cde44861e 36 bool menu = true;
NicolasV 4:d57cde44861e 37 bool min45 = false, min30 = false, min15 = false, min0 = false; // Indican si faltan X minutos para pico y placa.
NicolasV 4:d57cde44861e 38 bool alarma45 = false, alarma30 = false, alarma15 = false, alarma0 = false; // Indican si ya sonó o no la alarma correspondiente.
NicolasV 4:d57cde44861e 39 bool pico_y_placa = false; // Es verdadero si en el dia actual el carro tiene pico y placa, independientemente de la hora.
NicolasV 4:d57cde44861e 40 bool correccion = false; // Se identificaron rangos de horas para los cuales la configuración del reloj salía mal. Puede ser un problema de la librería o del integrado. Esta variable ayuda a mostrar y configurar la hora correcta.
NicolasV 4:d57cde44861e 41 int dia = 0, mes = 0, anno = 0, day = 1, hora = 0, min = 0; // Variables para almacenar las opciones de configuración del reloj.
NicolasV 4:d57cde44861e 42 int cambio = 0, diferencia = 0; // Variables del encoder.
NicolasV 4:d57cde44861e 43 int pos = 0;
tony63 0:4e0dfcf0e7ce 44
NicolasV 2:00db719ebd81 45 int main() {
NicolasV 3:2e823b16a4a1 46
NicolasV 4:d57cde44861e 47 carro = 1;
NicolasV 4:d57cde44861e 48 alarma = 0;
NicolasV 3:2e823b16a4a1 49
NicolasV 4:d57cde44861e 50 Rtc_Ds1307::Time_rtc tm = {};
NicolasV 2:00db719ebd81 51 GSM.baud(9600);
NicolasV 2:00db719ebd81 52 GSM.format(8,Serial::None,1);
NicolasV 3:2e823b16a4a1 53 t.start();
NicolasV 3:2e823b16a4a1 54
NicolasV 4:d57cde44861e 55 lcd.cls();
NicolasV 4:d57cde44861e 56 lcd.locate(0,0);
NicolasV 4:d57cde44861e 57 lcd.printf("**Pico y placa**");
NicolasV 4:d57cde44861e 58 wait(1);
NicolasV 4:d57cde44861e 59 // Animación de bienvenida:
NicolasV 4:d57cde44861e 60 for (int i = 0; i < 16; ++i) {
NicolasV 4:d57cde44861e 61 lcd.writeCommand(C2);
NicolasV 4:d57cde44861e 62 wait(0.1);
NicolasV 4:d57cde44861e 63 }
NicolasV 4:d57cde44861e 64 lcd.cls();
NicolasV 4:d57cde44861e 65
NicolasV 4:d57cde44861e 66 menu:
NicolasV 4:d57cde44861e 67 // En este menu se escoge entre ingresar la placa o configurar el reloj.
NicolasV 4:d57cde44861e 68 wait(0.3);
NicolasV 4:d57cde44861e 69 lcd.cls();
NicolasV 4:d57cde44861e 70 lcd.writeCommand(C1);
NicolasV 4:d57cde44861e 71 lcd.locate(0,0);
NicolasV 4:d57cde44861e 72 lcd.printf("Menu");
NicolasV 4:d57cde44861e 73 lcd.locate(0,1);
NicolasV 4:d57cde44861e 74 lcd.printf("1.Placa 2.Config");
NicolasV 4:d57cde44861e 75 lcd.locate(0,1);
NicolasV 4:d57cde44861e 76 lcd.printf("1");
NicolasV 4:d57cde44861e 77 //
NicolasV 4:d57cde44861e 78 menu = true;
NicolasV 4:d57cde44861e 79
NicolasV 4:d57cde44861e 80 while(true) {
NicolasV 4:d57cde44861e 81 if (!button3) {
NicolasV 4:d57cde44861e 82 menu = !menu;
NicolasV 4:d57cde44861e 83 if (menu) {
NicolasV 4:d57cde44861e 84 lcd.locate(0,1);
NicolasV 4:d57cde44861e 85 lcd.printf("1");
NicolasV 4:d57cde44861e 86 }
NicolasV 4:d57cde44861e 87 else {
NicolasV 4:d57cde44861e 88 lcd.locate(8,1);
NicolasV 4:d57cde44861e 89 lcd.printf("2");
NicolasV 4:d57cde44861e 90 }
NicolasV 4:d57cde44861e 91 wait(0.5);
NicolasV 4:d57cde44861e 92 }
NicolasV 3:2e823b16a4a1 93
NicolasV 4:d57cde44861e 94 if (!button4) {
NicolasV 4:d57cde44861e 95 wait(0.5);
NicolasV 4:d57cde44861e 96 if (menu) goto init;
NicolasV 4:d57cde44861e 97 if (!menu) goto config;
NicolasV 4:d57cde44861e 98 }
NicolasV 4:d57cde44861e 99 }
NicolasV 4:d57cde44861e 100
NicolasV 4:d57cde44861e 101 config:
NicolasV 4:d57cde44861e 102
NicolasV 4:d57cde44861e 103 pos = 5;
NicolasV 4:d57cde44861e 104 lcd.cls();
NicolasV 4:d57cde44861e 105 lcd.writeCommand(C1);
NicolasV 4:d57cde44861e 106 lcd.locate(0,1);
NicolasV 4:d57cde44861e 107 lcd.printf("DD/MM/YY HH:MM");
NicolasV 4:d57cde44861e 108 lcd.locate(0,0);
NicolasV 4:d57cde44861e 109 lcd.printf("Config. Dia");
NicolasV 4:d57cde44861e 110
NicolasV 4:d57cde44861e 111 // Se usa el botón del encoder para pasar la variable configurada y el encoder para ajustar su valor.
NicolasV 4:d57cde44861e 112 // Usando el pulsador se guarda la configuración.
NicolasV 4:d57cde44861e 113 while (true) {
NicolasV 4:d57cde44861e 114
NicolasV 4:d57cde44861e 115 diferencia=(encoder.getPulses() - cambio);
NicolasV 4:d57cde44861e 116 cambio=encoder.getPulses();
NicolasV 3:2e823b16a4a1 117
NicolasV 4:d57cde44861e 118 if (diferencia != 0) {
NicolasV 4:d57cde44861e 119
NicolasV 4:d57cde44861e 120 switch (pos) {
NicolasV 4:d57cde44861e 121 case 0:
NicolasV 4:d57cde44861e 122 dia += diferencia;
NicolasV 4:d57cde44861e 123 if (dia > 31) dia = 1;
NicolasV 4:d57cde44861e 124 if (dia < 1) dia = 31;
NicolasV 4:d57cde44861e 125 lcd.locate(0,1);
NicolasV 4:d57cde44861e 126 lcd.printf("%02d", dia);
NicolasV 4:d57cde44861e 127 break;
NicolasV 4:d57cde44861e 128 case 1:
NicolasV 4:d57cde44861e 129 mes += diferencia;
NicolasV 4:d57cde44861e 130 if (mes > 12) mes = 1;
NicolasV 4:d57cde44861e 131 if (mes < 1) mes = 12;
NicolasV 4:d57cde44861e 132 lcd.locate(3,1);
NicolasV 4:d57cde44861e 133 lcd.printf("%02d", mes);
NicolasV 4:d57cde44861e 134 break;
NicolasV 4:d57cde44861e 135 case 2:
NicolasV 4:d57cde44861e 136 anno += diferencia;
NicolasV 4:d57cde44861e 137 if (anno > 99) anno = 0;
NicolasV 4:d57cde44861e 138 if (anno < 0) anno = 99;
NicolasV 4:d57cde44861e 139 lcd.locate(6,1);
NicolasV 4:d57cde44861e 140 lcd.printf("%02d", anno);
NicolasV 4:d57cde44861e 141 break;
NicolasV 4:d57cde44861e 142 case 3:
NicolasV 4:d57cde44861e 143 hora += diferencia;
NicolasV 4:d57cde44861e 144 if (hora > 23) hora = 0;
NicolasV 4:d57cde44861e 145 if (hora < 0) hora = 23;
NicolasV 4:d57cde44861e 146 lcd.locate(11,1);
NicolasV 4:d57cde44861e 147 lcd.printf("%02d", hora);
NicolasV 4:d57cde44861e 148 break;
NicolasV 4:d57cde44861e 149 case 4:
NicolasV 4:d57cde44861e 150 min += diferencia;
NicolasV 4:d57cde44861e 151 if (min > 59) min = 0;
NicolasV 4:d57cde44861e 152 if (min < 0) min = 59;
NicolasV 4:d57cde44861e 153 lcd.locate(14,1);
NicolasV 4:d57cde44861e 154 lcd.printf("%02d", min);
NicolasV 4:d57cde44861e 155 break;
NicolasV 4:d57cde44861e 156 case 5:
NicolasV 4:d57cde44861e 157 day += diferencia;
NicolasV 4:d57cde44861e 158 if (day < 1) day = 7;
NicolasV 4:d57cde44861e 159 if (day > 7) day = 1;
NicolasV 4:d57cde44861e 160 lcd.locate(13, 0);
NicolasV 4:d57cde44861e 161 lcd.printf("%s", dias[day]);
NicolasV 4:d57cde44861e 162 break;
NicolasV 4:d57cde44861e 163 }
NicolasV 4:d57cde44861e 164 }
NicolasV 4:d57cde44861e 165
NicolasV 4:d57cde44861e 166 if (!button3) {
NicolasV 4:d57cde44861e 167 if (++pos > 5) pos = 0;
NicolasV 4:d57cde44861e 168 wait(0.3);
NicolasV 4:d57cde44861e 169 }
NicolasV 4:d57cde44861e 170 if (!button4) {
NicolasV 4:d57cde44861e 171
NicolasV 4:d57cde44861e 172 if ((hora >= 18 && hora <= 23) || (hora >= 0 && hora <= 3) || (hora >= 8 && hora <= 13))
NicolasV 4:d57cde44861e 173 correccion = true;
NicolasV 4:d57cde44861e 174 else
NicolasV 4:d57cde44861e 175 correccion = false;
NicolasV 4:d57cde44861e 176
NicolasV 4:d57cde44861e 177 wait(0.3);
NicolasV 4:d57cde44861e 178 lcd.cls();
NicolasV 4:d57cde44861e 179 lcd.printf("Guardado!");
NicolasV 4:d57cde44861e 180 menu = true;
NicolasV 4:d57cde44861e 181 tm.date = dia;
NicolasV 4:d57cde44861e 182 tm.mon = mes;
NicolasV 4:d57cde44861e 183 tm.year = 2000 + anno;
NicolasV 4:d57cde44861e 184 tm.hour = hora;
NicolasV 4:d57cde44861e 185 tm.min = min;
NicolasV 4:d57cde44861e 186 tm.sec = 0;
NicolasV 4:d57cde44861e 187 tm.wday = day;
NicolasV 4:d57cde44861e 188 rtc.setTime(tm, true, false);
NicolasV 4:d57cde44861e 189 wait(1);
NicolasV 4:d57cde44861e 190 lcd.cls();
NicolasV 4:d57cde44861e 191 goto menu;
NicolasV 4:d57cde44861e 192 }
NicolasV 3:2e823b16a4a1 193 }
NicolasV 3:2e823b16a4a1 194
NicolasV 3:2e823b16a4a1 195 init:
NicolasV 3:2e823b16a4a1 196
NicolasV 4:d57cde44861e 197 // Se escribe la placa usando el encoder.
NicolasV 3:2e823b16a4a1 198 lcd.cls();
NicolasV 3:2e823b16a4a1 199 lcd.writeCommand(C1);
NicolasV 4:d57cde44861e 200 lcd.locate(0,0);
NicolasV 4:d57cde44861e 201 lcd.printf("Ingrese placa:");
tony63 0:4e0dfcf0e7ce 202 lcd.locate(0,1);
NicolasV 4:d57cde44861e 203 lcd.printf("%c%c%c%1d%1d%1d", abc[p1], abc[p2], abc[p3], p4, p5, p6);
NicolasV 4:d57cde44861e 204 lcd.writeCommand(0xC0); // Cursor en (0,1)
NicolasV 4:d57cde44861e 205 pos = 0;
NicolasV 3:2e823b16a4a1 206
NicolasV 2:00db719ebd81 207 while(true) {
tony63 0:4e0dfcf0e7ce 208
NicolasV 4:d57cde44861e 209 diferencia=(encoder.getPulses() - cambio);
tony63 0:4e0dfcf0e7ce 210 cambio=encoder.getPulses();
NicolasV 2:00db719ebd81 211
NicolasV 4:d57cde44861e 212 if (diferencia != 0) {
NicolasV 2:00db719ebd81 213 switch (pos) {
NicolasV 4:d57cde44861e 214 case 0:
NicolasV 4:d57cde44861e 215 lcd.locate(0,1);
NicolasV 4:d57cde44861e 216 p1 += diferencia;
NicolasV 4:d57cde44861e 217 if (p1 > 25) p1 = 0;
NicolasV 4:d57cde44861e 218 if (p1 < 0) p1 = 25;
NicolasV 4:d57cde44861e 219 lcd.printf("%c", abc[p1]);
NicolasV 4:d57cde44861e 220 break;
NicolasV 2:00db719ebd81 221 case 1:
NicolasV 4:d57cde44861e 222 lcd.locate(1,1);
NicolasV 4:d57cde44861e 223 p2 += diferencia;
NicolasV 4:d57cde44861e 224 if (p2 > 25) p2 = 0;
NicolasV 4:d57cde44861e 225 if (p2 < 0) p2 = 25;
NicolasV 4:d57cde44861e 226 lcd.printf("%c", abc[p2]);
NicolasV 2:00db719ebd81 227 break;
NicolasV 3:2e823b16a4a1 228 case 2:
NicolasV 4:d57cde44861e 229 lcd.locate(2,1);
NicolasV 4:d57cde44861e 230 p3 += diferencia;
NicolasV 4:d57cde44861e 231 if (p3 > 25) p3 = 0;
NicolasV 4:d57cde44861e 232 if (p3 < 0) p3 = 25;
NicolasV 4:d57cde44861e 233 lcd.printf("%c", abc[p3]);
NicolasV 2:00db719ebd81 234 break;
NicolasV 3:2e823b16a4a1 235 case 3:
NicolasV 3:2e823b16a4a1 236 lcd.locate(3,1);
NicolasV 4:d57cde44861e 237 p4 += diferencia;
NicolasV 4:d57cde44861e 238 if (p4 > 9) p4 = 0;
NicolasV 4:d57cde44861e 239 if (p4 < 0) p4 = 9;
NicolasV 4:d57cde44861e 240 lcd.printf("%d", p4);
NicolasV 4:d57cde44861e 241 break;
NicolasV 4:d57cde44861e 242 case 4:
NicolasV 4:d57cde44861e 243 lcd.locate(4,1);
NicolasV 4:d57cde44861e 244 p5 += diferencia;
NicolasV 4:d57cde44861e 245 if (p5 > 9) p5 = 0;
NicolasV 4:d57cde44861e 246 if (p5 < 0) p5 = 9;
NicolasV 4:d57cde44861e 247 lcd.printf("%d", p5);
NicolasV 4:d57cde44861e 248 break;
NicolasV 4:d57cde44861e 249 case 5:
NicolasV 4:d57cde44861e 250 lcd.locate(5,1);
NicolasV 4:d57cde44861e 251 p6 += diferencia;
NicolasV 4:d57cde44861e 252 if (p6 > 9) p6 = 0;
NicolasV 4:d57cde44861e 253 if (p6 < 0) p6 = 9;
NicolasV 4:d57cde44861e 254 lcd.printf("%d", p6);
NicolasV 2:00db719ebd81 255 break;
NicolasV 3:2e823b16a4a1 256 }
NicolasV 4:d57cde44861e 257 }
NicolasV 2:00db719ebd81 258
NicolasV 4:d57cde44861e 259 if (!button3) {
NicolasV 4:d57cde44861e 260 led2 = !led2;
NicolasV 4:d57cde44861e 261 pos++;
NicolasV 4:d57cde44861e 262 pos = pos % 6;
NicolasV 3:2e823b16a4a1 263 wait(0.2);
NicolasV 3:2e823b16a4a1 264 }
tony63 0:4e0dfcf0e7ce 265
NicolasV 4:d57cde44861e 266 if (!button4) {
NicolasV 3:2e823b16a4a1 267 lcd.cls();
NicolasV 3:2e823b16a4a1 268 lcd.locate(0,0);
NicolasV 4:d57cde44861e 269 lcd.printf("Guardado!");
NicolasV 4:d57cde44861e 270 wait(2);
NicolasV 3:2e823b16a4a1 271 break;
tony63 0:4e0dfcf0e7ce 272 }
tony63 0:4e0dfcf0e7ce 273 wait(0.1);
tony63 0:4e0dfcf0e7ce 274 }
NicolasV 3:2e823b16a4a1 275
NicolasV 4:d57cde44861e 276 reloj:
NicolasV 4:d57cde44861e 277
NicolasV 4:d57cde44861e 278 // En esta sección se muestran la placa, el reloj y los avisos de alarma.
NicolasV 4:d57cde44861e 279 lcd.writeCommand(C4);
tony63 0:4e0dfcf0e7ce 280 lcd.cls();
NicolasV 4:d57cde44861e 281 lcd.locate(0,0);
NicolasV 4:d57cde44861e 282 lcd.printf("%c%c%c%d%d%d", abc[p1], abc[p2], abc[p3], p4, p5, p6);
NicolasV 4:d57cde44861e 283
NicolasV 4:d57cde44861e 284 while (true) {
NicolasV 4:d57cde44861e 285
NicolasV 4:d57cde44861e 286 if (!button4) {
NicolasV 4:d57cde44861e 287 wait(0.3);
NicolasV 4:d57cde44861e 288 goto menu;
NicolasV 4:d57cde44861e 289 }
NicolasV 4:d57cde44861e 290
NicolasV 4:d57cde44861e 291 lcd.locate(0,1);
NicolasV 4:d57cde44861e 292
NicolasV 4:d57cde44861e 293 if (rtc.getTime(tm)) {
NicolasV 4:d57cde44861e 294
NicolasV 4:d57cde44861e 295 if (((tm.hour >= 22 && tm.hour <= 27) || (tm.hour >= 4 && tm.hour <= 7) || (tm.hour >= 12 && tm.hour <= 15)) && correccion)
NicolasV 4:d57cde44861e 296 lcd.printf("%02d:%02d:%02d %s", tm.hour-4, tm.min, tm.sec, dias[tm.wday]);
NicolasV 4:d57cde44861e 297 else
NicolasV 4:d57cde44861e 298 lcd.printf("%02d:%02d:%02d %s", tm.hour, tm.min, tm.sec, dias[tm.wday]);
tony63 0:4e0dfcf0e7ce 299
NicolasV 4:d57cde44861e 300 wait(1);
NicolasV 4:d57cde44861e 301 }
NicolasV 4:d57cde44861e 302
NicolasV 4:d57cde44861e 303 // Se checkea si el automovil tiene pico y placa (Hora y dia): *********
NicolasV 3:2e823b16a4a1 304
NicolasV 4:d57cde44861e 305 if (tm.wday == 2 && p6 >= 2 && p6 <= 5) { // Lunes
NicolasV 4:d57cde44861e 306 pico_y_placa = true;
NicolasV 4:d57cde44861e 307 lcd.locate(9,0);
NicolasV 4:d57cde44861e 308 lcd.printf("Hoy P&P");
NicolasV 4:d57cde44861e 309 }
NicolasV 4:d57cde44861e 310 else if (tm.wday == 3 && p6 >= 6 && p6 <= 9) { // Martes
NicolasV 4:d57cde44861e 311 pico_y_placa = true;
NicolasV 4:d57cde44861e 312 lcd.locate(9,0);
NicolasV 4:d57cde44861e 313 lcd.printf("Hoy P&P");
NicolasV 4:d57cde44861e 314 }
NicolasV 4:d57cde44861e 315 else if (tm.wday == 4 && p6 >= 0 && p6 <= 3) { // Miercoles
NicolasV 4:d57cde44861e 316 pico_y_placa = true;
NicolasV 4:d57cde44861e 317 lcd.locate(9,0);
NicolasV 4:d57cde44861e 318 lcd.printf("Hoy P&P");
NicolasV 4:d57cde44861e 319 }
NicolasV 4:d57cde44861e 320 else if (tm.wday == 5 && p6 >= 4 && p6 <= 7) { // Jueves
NicolasV 4:d57cde44861e 321 pico_y_placa = true;
NicolasV 4:d57cde44861e 322 lcd.locate(9,0);
NicolasV 4:d57cde44861e 323 lcd.printf("Hoy P&P");
NicolasV 4:d57cde44861e 324 }
NicolasV 4:d57cde44861e 325 else if (tm.wday == 6 && (p6 == 8 || p6 == 9 || p6 == 0 || p6 == 1)) { // Viernes
NicolasV 4:d57cde44861e 326 pico_y_placa = true;
NicolasV 4:d57cde44861e 327 lcd.locate(9,0);
NicolasV 4:d57cde44861e 328 lcd.printf("Hoy P&P");
NicolasV 4:d57cde44861e 329 }
NicolasV 4:d57cde44861e 330 else {
NicolasV 4:d57cde44861e 331 pico_y_placa = false;
NicolasV 4:d57cde44861e 332 lcd.locate(9,0);
NicolasV 4:d57cde44861e 333 lcd.printf(" ");
NicolasV 4:d57cde44861e 334 }
NicolasV 2:00db719ebd81 335
NicolasV 4:d57cde44861e 336 int hora_c;
NicolasV 3:2e823b16a4a1 337
NicolasV 4:d57cde44861e 338 if (((tm.hour >= 22 && tm.hour <= 27) || (tm.hour >= 4 && tm.hour <= 7) || (tm.hour >= 12 && tm.hour <= 16)) && correccion)
NicolasV 4:d57cde44861e 339 hora_c = 100*(tm.hour-4) + tm.min;
NicolasV 4:d57cde44861e 340 else
NicolasV 4:d57cde44861e 341 hora_c = 100*tm.hour + tm.min;
tony63 0:4e0dfcf0e7ce 342
NicolasV 4:d57cde44861e 343 if ((hora_c >= 700 && hora_c < 830) || (hora_c >= 1730 && hora_c < 1900))
NicolasV 4:d57cde44861e 344 min0 = true;
NicolasV 4:d57cde44861e 345 else
NicolasV 4:d57cde44861e 346 min0 = false;
NicolasV 4:d57cde44861e 347
NicolasV 4:d57cde44861e 348 if ((hora_c >= 615 && hora_c < 700) || (hora_c >= 1645 && hora_c < 1730))
NicolasV 4:d57cde44861e 349 min45 = true;
NicolasV 4:d57cde44861e 350 else
NicolasV 4:d57cde44861e 351 min45 = false;
NicolasV 4:d57cde44861e 352
NicolasV 4:d57cde44861e 353 if ((hora_c >= 630 && hora_c < 700) || (hora_c >= 1700 && hora_c < 1730))
NicolasV 4:d57cde44861e 354 min30 = true;
NicolasV 4:d57cde44861e 355 else
NicolasV 4:d57cde44861e 356 min30 = false;
NicolasV 4:d57cde44861e 357
NicolasV 4:d57cde44861e 358 if ((hora_c >= 645 && hora_c < 700) || (hora_c >= 1715 && hora_c < 1730))
NicolasV 4:d57cde44861e 359 min15 = true;
NicolasV 4:d57cde44861e 360 else
NicolasV 4:d57cde44861e 361 min15 = false;
NicolasV 4:d57cde44861e 362
NicolasV 4:d57cde44861e 363 if((hora_c == 830 || hora_c == 1900) && tm.sec < 10) {
NicolasV 4:d57cde44861e 364 alarma0 = false; alarma15 = false;
NicolasV 4:d57cde44861e 365 alarma30 = false; alarma45 = false;
NicolasV 3:2e823b16a4a1 366 }
NicolasV 4:d57cde44861e 367
NicolasV 4:d57cde44861e 368
NicolasV 4:d57cde44861e 369 // Se disparan las alarmas: ********************************************
NicolasV 4:d57cde44861e 370
NicolasV 4:d57cde44861e 371 if (pico_y_placa && min45 && !alarma45) {
NicolasV 4:d57cde44861e 372 alarma45 = true;
NicolasV 4:d57cde44861e 373 lcd.cls();
NicolasV 4:d57cde44861e 374 lcd.printf(" *** Faltan *** \n *** 45 min ***");
NicolasV 4:d57cde44861e 375 for (int a = 0; a < 10; ++a) {
NicolasV 4:d57cde44861e 376 alarma = !alarma;
NicolasV 4:d57cde44861e 377 wait(1);
NicolasV 4:d57cde44861e 378 }
NicolasV 4:d57cde44861e 379 goto reloj;
NicolasV 4:d57cde44861e 380 }
NicolasV 4:d57cde44861e 381 if (pico_y_placa && min30 && !alarma30) {
NicolasV 4:d57cde44861e 382 alarma30 = true;
NicolasV 4:d57cde44861e 383 lcd.cls();
NicolasV 4:d57cde44861e 384 lcd.printf(" *** Faltan *** \n *** 30 min ***");
NicolasV 4:d57cde44861e 385 for (int a = 0; a < 20; ++a) {
NicolasV 4:d57cde44861e 386 alarma = !alarma;
NicolasV 4:d57cde44861e 387 wait(0.5);
NicolasV 4:d57cde44861e 388 }
NicolasV 4:d57cde44861e 389 goto reloj;
NicolasV 4:d57cde44861e 390 }
NicolasV 4:d57cde44861e 391 if (pico_y_placa && min15 && !alarma15) {
NicolasV 4:d57cde44861e 392 alarma15 = true;
NicolasV 4:d57cde44861e 393 lcd.cls();
NicolasV 4:d57cde44861e 394 lcd.printf(" *** Faltan *** \n *** 15 min ***");
NicolasV 4:d57cde44861e 395 for (int a = 0; a < 40; ++a) {
NicolasV 4:d57cde44861e 396 alarma = !alarma;
NicolasV 4:d57cde44861e 397 wait(0.25);
NicolasV 4:d57cde44861e 398 }
NicolasV 4:d57cde44861e 399 goto reloj;
NicolasV 4:d57cde44861e 400 }
NicolasV 4:d57cde44861e 401 if (pico_y_placa && min0 && !alarma0) {
NicolasV 4:d57cde44861e 402 alarma0 = true;
NicolasV 4:d57cde44861e 403 lcd.cls();
NicolasV 4:d57cde44861e 404 lcd.printf(" *** Pico y *** \n *** placa *** ");
NicolasV 4:d57cde44861e 405 alarma = 1;
NicolasV 4:d57cde44861e 406 carro = 0;
NicolasV 4:d57cde44861e 407 goto reloj;
NicolasV 4:d57cde44861e 408 }
NicolasV 4:d57cde44861e 409 if (!pico_y_placa) {
NicolasV 4:d57cde44861e 410 alarma = 0;
NicolasV 4:d57cde44861e 411 carro = 1;
NicolasV 4:d57cde44861e 412 }
NicolasV 3:2e823b16a4a1 413 }
NicolasV 3:2e823b16a4a1 414 }