![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Reloj con alarma y snooze
Dependencies: RTC-DS1307-Modificada TextLCD mbed QEI
main.cpp@2:32f3a407a8ea, 2016-05-19 (annotated)
- Committer:
- Susanaranjo
- Date:
- Thu May 19 19:18:49 2016 +0000
- Revision:
- 2:32f3a407a8ea
- Parent:
- 0:1c2ae7e04432
Alarma con Snooze y encoder
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Susanaranjo | 0:1c2ae7e04432 | 1 | #include "mbed.h" |
Susanaranjo | 0:1c2ae7e04432 | 2 | #include "Rtc_Ds1307.h" |
Susanaranjo | 0:1c2ae7e04432 | 3 | #include "TextLCD.h" |
Susanaranjo | 2:32f3a407a8ea | 4 | #include "QEI.h" |
Susanaranjo | 0:1c2ae7e04432 | 5 | |
Susanaranjo | 0:1c2ae7e04432 | 6 | //Configuración de la pantalla |
Susanaranjo | 0:1c2ae7e04432 | 7 | TextLCD lcd(PTE20,PTE21,PTE22,PTE23,PTE29,PTE30, TextLCD::LCD16x2); //Rs, E, d4, d5, d6, d7 |
Susanaranjo | 0:1c2ae7e04432 | 8 | |
Susanaranjo | 0:1c2ae7e04432 | 9 | //Configuración del reloj |
Susanaranjo | 0:1c2ae7e04432 | 10 | Rtc_Ds1307 rtc(PTE0, PTE1); // SDA, SCL |
Susanaranjo | 0:1c2ae7e04432 | 11 | |
Susanaranjo | 0:1c2ae7e04432 | 12 | //Configuración del puerto |
Susanaranjo | 0:1c2ae7e04432 | 13 | Serial pc(USBTX, USBRX, "pc"); |
Susanaranjo | 0:1c2ae7e04432 | 14 | |
Susanaranjo | 2:32f3a407a8ea | 15 | //Configuración del encoder |
Susanaranjo | 2:32f3a407a8ea | 16 | QEI encoder(PTD5, PTD0, NC,624); |
Susanaranjo | 2:32f3a407a8ea | 17 | |
Susanaranjo | 0:1c2ae7e04432 | 18 | DigitalIn alarma(PTC12); |
Susanaranjo | 0:1c2ae7e04432 | 19 | DigitalIn snooze(PTC13); |
Susanaranjo | 2:32f3a407a8ea | 20 | DigitalIn alarmaE(PTC16); |
Susanaranjo | 0:1c2ae7e04432 | 21 | PwmOut speaker(PTA13); |
Susanaranjo | 0:1c2ae7e04432 | 22 | |
Susanaranjo | 0:1c2ae7e04432 | 23 | |
Susanaranjo | 0:1c2ae7e04432 | 24 | char buffer[128]; |
Susanaranjo | 0:1c2ae7e04432 | 25 | int readptr = 0; |
Susanaranjo | 0:1c2ae7e04432 | 26 | int hora=0; |
Susanaranjo | 2:32f3a407a8ea | 27 | int hora2=0; |
Susanaranjo | 0:1c2ae7e04432 | 28 | int minutos=0; |
Susanaranjo | 2:32f3a407a8ea | 29 | int minutos2=0; |
Susanaranjo | 0:1c2ae7e04432 | 30 | int seg=0; |
Susanaranjo | 2:32f3a407a8ea | 31 | int seg2=0; |
Susanaranjo | 0:1c2ae7e04432 | 32 | int mes=0; |
Susanaranjo | 2:32f3a407a8ea | 33 | int mes2=0; |
Susanaranjo | 0:1c2ae7e04432 | 34 | int fecha=0; |
Susanaranjo | 2:32f3a407a8ea | 35 | int fecha2=0; |
Susanaranjo | 0:1c2ae7e04432 | 36 | int anno=0; |
Susanaranjo | 2:32f3a407a8ea | 37 | int anno2=0; |
Susanaranjo | 0:1c2ae7e04432 | 38 | int pulsador; |
Susanaranjo | 0:1c2ae7e04432 | 39 | int pulsador2; |
Susanaranjo | 0:1c2ae7e04432 | 40 | int a=0; |
Susanaranjo | 2:32f3a407a8ea | 41 | int b=0; |
Susanaranjo | 2:32f3a407a8ea | 42 | int pulsos=0; |
Susanaranjo | 2:32f3a407a8ea | 43 | int diferencia=0; |
Susanaranjo | 2:32f3a407a8ea | 44 | int alarma2=0; |
Susanaranjo | 0:1c2ae7e04432 | 45 | |
Susanaranjo | 0:1c2ae7e04432 | 46 | |
Susanaranjo | 0:1c2ae7e04432 | 47 | int main() |
Susanaranjo | 0:1c2ae7e04432 | 48 | { |
Susanaranjo | 0:1c2ae7e04432 | 49 | char c; |
Susanaranjo | 0:1c2ae7e04432 | 50 | Rtc_Ds1307::Time_rtc tm = {}; |
Susanaranjo | 0:1c2ae7e04432 | 51 | |
Susanaranjo | 0:1c2ae7e04432 | 52 | lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 53 | lcd.locate(0,0); |
Susanaranjo | 0:1c2ae7e04432 | 54 | lcd.printf("Configurando"); |
Susanaranjo | 0:1c2ae7e04432 | 55 | lcd.locate(0,1); |
Susanaranjo | 0:1c2ae7e04432 | 56 | lcd.printf("el reloj"); |
Susanaranjo | 0:1c2ae7e04432 | 57 | |
Susanaranjo | 0:1c2ae7e04432 | 58 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 59 | pc.printf("* Configurar el reloj *\n"); |
Susanaranjo | 0:1c2ae7e04432 | 60 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 61 | |
Susanaranjo | 0:1c2ae7e04432 | 62 | while(1) { |
Susanaranjo | 0:1c2ae7e04432 | 63 | |
Susanaranjo | 0:1c2ae7e04432 | 64 | |
Susanaranjo | 0:1c2ae7e04432 | 65 | pc.printf("Ingrese la fecha (entre 1 y 31)"); |
Susanaranjo | 0:1c2ae7e04432 | 66 | pc.scanf("%d", &tm.date); |
Susanaranjo | 0:1c2ae7e04432 | 67 | pc.printf("Ingrese el mes (entre 1 y 12)"); |
Susanaranjo | 0:1c2ae7e04432 | 68 | pc.scanf("%d", &tm.mon); |
Susanaranjo | 0:1c2ae7e04432 | 69 | pc.printf("Ingrese el anno (ejemplo: 2016)"); |
Susanaranjo | 0:1c2ae7e04432 | 70 | pc.scanf("%d", &tm.year); |
Susanaranjo | 0:1c2ae7e04432 | 71 | pc.printf("Ingrese la hora (entre 0 y 23)"); |
Susanaranjo | 0:1c2ae7e04432 | 72 | pc.scanf("%d", &tm.hour); |
Susanaranjo | 0:1c2ae7e04432 | 73 | pc.printf("Ingrese los minutos (entre 0 y 59)"); |
Susanaranjo | 0:1c2ae7e04432 | 74 | pc.scanf("%d", &tm.min); |
Susanaranjo | 0:1c2ae7e04432 | 75 | pc.printf("Ingrese los segundos (entre 0 y 59)"); |
Susanaranjo | 0:1c2ae7e04432 | 76 | pc.scanf("%d", &tm.sec); |
Susanaranjo | 0:1c2ae7e04432 | 77 | pc.printf("Ingrese el dia (siendo Domingo=1)"); |
Susanaranjo | 0:1c2ae7e04432 | 78 | pc.scanf("%d", &tm.wday); |
Susanaranjo | 0:1c2ae7e04432 | 79 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 80 | pc.printf("Configurando el reloj\n"); |
Susanaranjo | 0:1c2ae7e04432 | 81 | |
Susanaranjo | 0:1c2ae7e04432 | 82 | |
Susanaranjo | 0:1c2ae7e04432 | 83 | while(pc.readable()) { |
Susanaranjo | 0:1c2ae7e04432 | 84 | pc.getc(); |
Susanaranjo | 0:1c2ae7e04432 | 85 | rtc.setTime(tm, false, false);} |
Susanaranjo | 0:1c2ae7e04432 | 86 | |
Susanaranjo | 0:1c2ae7e04432 | 87 | wait_ms(200); |
Susanaranjo | 0:1c2ae7e04432 | 88 | |
Susanaranjo | 0:1c2ae7e04432 | 89 | pc.printf("Inicializando el reloj\n"); |
Susanaranjo | 0:1c2ae7e04432 | 90 | rtc.startClock(); |
Susanaranjo | 0:1c2ae7e04432 | 91 | |
Susanaranjo | 0:1c2ae7e04432 | 92 | wait_ms(200); |
Susanaranjo | 0:1c2ae7e04432 | 93 | |
Susanaranjo | 0:1c2ae7e04432 | 94 | pc.printf("Leyendo el reloj\n"); |
Susanaranjo | 0:1c2ae7e04432 | 95 | |
Susanaranjo | 0:1c2ae7e04432 | 96 | loop1: if (rtc.getTime(tm) ) { |
Susanaranjo | 0:1c2ae7e04432 | 97 | pulsador=alarma.read(); |
Susanaranjo | 0:1c2ae7e04432 | 98 | |
Susanaranjo | 0:1c2ae7e04432 | 99 | a=(abs(tm.hour-hora))+(abs(tm.min-minutos))+(abs(tm.sec-seg))+(abs(tm.mon-mes))+(abs(tm.date-fecha))+(abs(tm.year-anno)); // Compara la hora y la fecha actual con la fecha y hora de la alarma |
Susanaranjo | 2:32f3a407a8ea | 100 | b=(abs(tm.hour-hora2))+(abs(tm.min-minutos2))+(abs(tm.sec-seg2))+(abs(tm.mon-mes2))+(abs(tm.date-fecha2))+(abs(tm.year-anno2)); // Compara la hora y la fecha actual con la fecha y hora de la alarma |
Susanaranjo | 0:1c2ae7e04432 | 101 | |
Susanaranjo | 0:1c2ae7e04432 | 102 | //pc.printf("%d\n",a); |
Susanaranjo | 0:1c2ae7e04432 | 103 | |
Susanaranjo | 2:32f3a407a8ea | 104 | if (a*b==0) |
Susanaranjo | 0:1c2ae7e04432 | 105 | { |
Susanaranjo | 0:1c2ae7e04432 | 106 | loop3: lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 107 | lcd.printf("ALARMA"); |
Susanaranjo | 0:1c2ae7e04432 | 108 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 109 | pc.printf("* ALARMA *\n"); |
Susanaranjo | 0:1c2ae7e04432 | 110 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 111 | speaker.period(1.0/500.0); |
Susanaranjo | 0:1c2ae7e04432 | 112 | speaker=0.5; |
Susanaranjo | 0:1c2ae7e04432 | 113 | |
Susanaranjo | 0:1c2ae7e04432 | 114 | loop4: pulsador2=snooze.read(); // Estado del pulsador para detener o posponer la alarma |
Susanaranjo | 0:1c2ae7e04432 | 115 | |
Susanaranjo | 0:1c2ae7e04432 | 116 | if (pulsador2==0){ |
Susanaranjo | 0:1c2ae7e04432 | 117 | speaker=0.0; |
Susanaranjo | 0:1c2ae7e04432 | 118 | pc.printf("Pulsar 5 segundos para detener\n"); |
Susanaranjo | 0:1c2ae7e04432 | 119 | lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 120 | lcd.printf("Mantenga pulsado"); |
Susanaranjo | 0:1c2ae7e04432 | 121 | lcd.locate(0,1); |
Susanaranjo | 0:1c2ae7e04432 | 122 | lcd.printf("para detener"); |
Susanaranjo | 0:1c2ae7e04432 | 123 | wait(5); |
Susanaranjo | 0:1c2ae7e04432 | 124 | pulsador2=snooze.read(); |
Susanaranjo | 0:1c2ae7e04432 | 125 | if (pulsador2==0){ // Si despues de 5 segundos el pulsador todavia está oprimido, se detiene la alarma |
Susanaranjo | 0:1c2ae7e04432 | 126 | lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 127 | lcd.printf("Alarma"); |
Susanaranjo | 0:1c2ae7e04432 | 128 | lcd.locate(0,1); |
Susanaranjo | 0:1c2ae7e04432 | 129 | lcd.printf("desactivada"); |
Susanaranjo | 0:1c2ae7e04432 | 130 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 131 | pc.printf("* Alarma desactivada *\n"); |
Susanaranjo | 0:1c2ae7e04432 | 132 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 133 | wait(2); |
Susanaranjo | 0:1c2ae7e04432 | 134 | goto loop1; |
Susanaranjo | 0:1c2ae7e04432 | 135 | }else{ // Si el pulsador ya no está oprimido, se pospone la alarma un minuto |
Susanaranjo | 0:1c2ae7e04432 | 136 | lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 137 | lcd.printf("Snooze"); |
Susanaranjo | 0:1c2ae7e04432 | 138 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 139 | pc.printf("* Snooze *\n"); |
Susanaranjo | 0:1c2ae7e04432 | 140 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 141 | wait(60); |
Susanaranjo | 0:1c2ae7e04432 | 142 | goto loop3; |
Susanaranjo | 0:1c2ae7e04432 | 143 | } |
Susanaranjo | 0:1c2ae7e04432 | 144 | |
Susanaranjo | 0:1c2ae7e04432 | 145 | }else { |
Susanaranjo | 0:1c2ae7e04432 | 146 | goto loop4; } |
Susanaranjo | 0:1c2ae7e04432 | 147 | } |
Susanaranjo | 0:1c2ae7e04432 | 148 | |
Susanaranjo | 0:1c2ae7e04432 | 149 | //pc.printf("La hora actual es: %02d:%02d:%02d\n", tm.hour, tm.min, tm.sec); |
Susanaranjo | 0:1c2ae7e04432 | 150 | //pc.printf("La fecha actual es : %s, %02d/%02d/%04d\n", rtc.weekdayToString(tm.wday), tm.mon, tm.date, tm.year); |
Susanaranjo | 0:1c2ae7e04432 | 151 | |
Susanaranjo | 0:1c2ae7e04432 | 152 | else if (pulsador==0) { |
Susanaranjo | 0:1c2ae7e04432 | 153 | lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 154 | lcd.printf("Ver/Configurar"); |
Susanaranjo | 0:1c2ae7e04432 | 155 | lcd.locate(0,1); |
Susanaranjo | 0:1c2ae7e04432 | 156 | lcd.printf("alarma"); |
Susanaranjo | 0:1c2ae7e04432 | 157 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 158 | pc.printf("* alarma - configurar alarma *\n"); |
Susanaranjo | 0:1c2ae7e04432 | 159 | pc.printf("* ver - ver alarma *\n"); |
Susanaranjo | 0:1c2ae7e04432 | 160 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 161 | |
Susanaranjo | 0:1c2ae7e04432 | 162 | loop2: readptr = 0; |
Susanaranjo | 0:1c2ae7e04432 | 163 | |
Susanaranjo | 0:1c2ae7e04432 | 164 | //Obtengo la cadena de caracteres correspondiente a la orden |
Susanaranjo | 0:1c2ae7e04432 | 165 | |
Susanaranjo | 0:1c2ae7e04432 | 166 | while( (c = pc.getc()) != '\n') { |
Susanaranjo | 0:1c2ae7e04432 | 167 | buffer[readptr++] = c; } |
Susanaranjo | 0:1c2ae7e04432 | 168 | buffer[readptr++] = 0; |
Susanaranjo | 0:1c2ae7e04432 | 169 | |
Susanaranjo | 2:32f3a407a8ea | 170 | // Configurar alarma desde el computador |
Susanaranjo | 0:1c2ae7e04432 | 171 | if (strncmp(buffer, "alarma", 6) == 0) { |
Susanaranjo | 0:1c2ae7e04432 | 172 | |
Susanaranjo | 0:1c2ae7e04432 | 173 | lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 174 | lcd.printf("Configurando"); |
Susanaranjo | 0:1c2ae7e04432 | 175 | lcd.locate(0,1); |
Susanaranjo | 0:1c2ae7e04432 | 176 | lcd.printf("alarma"); |
Susanaranjo | 0:1c2ae7e04432 | 177 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 178 | pc.printf("* Nueva alarma *\n"); |
Susanaranjo | 0:1c2ae7e04432 | 179 | pc.printf("Fecha de la alarma (0..31)"); |
Susanaranjo | 0:1c2ae7e04432 | 180 | pc.scanf("%d", &fecha); |
Susanaranjo | 0:1c2ae7e04432 | 181 | pc.printf("Mes de la alarma (1..12)"); |
Susanaranjo | 0:1c2ae7e04432 | 182 | pc.scanf("%d", &mes); |
Susanaranjo | 0:1c2ae7e04432 | 183 | pc.printf("Anno de la alarma"); |
Susanaranjo | 0:1c2ae7e04432 | 184 | pc.scanf("%d", &anno); |
Susanaranjo | 0:1c2ae7e04432 | 185 | pc.printf("Hora de la alarma (0..23)"); |
Susanaranjo | 0:1c2ae7e04432 | 186 | pc.scanf("%d", &hora); |
Susanaranjo | 0:1c2ae7e04432 | 187 | pc.printf("Minutos de la alarma (0..59)"); |
Susanaranjo | 0:1c2ae7e04432 | 188 | pc.scanf("%d",&minutos); |
Susanaranjo | 0:1c2ae7e04432 | 189 | pc.printf("Segundos de la alarma (0..59)"); |
Susanaranjo | 0:1c2ae7e04432 | 190 | pc.scanf("%d", &seg); |
Susanaranjo | 0:1c2ae7e04432 | 191 | pc.printf("* Fin de la configuracion *\n"); |
Susanaranjo | 0:1c2ae7e04432 | 192 | pc.printf("*************************************\n"); |
Susanaranjo | 0:1c2ae7e04432 | 193 | lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 194 | lcd.printf("Fin de la configuracion"); |
Susanaranjo | 0:1c2ae7e04432 | 195 | wait_ms(500); |
Susanaranjo | 0:1c2ae7e04432 | 196 | goto loop1; |
Susanaranjo | 0:1c2ae7e04432 | 197 | |
Susanaranjo | 0:1c2ae7e04432 | 198 | } else if (strncmp(buffer, "ver", 3) == 0) { |
Susanaranjo | 0:1c2ae7e04432 | 199 | |
Susanaranjo | 0:1c2ae7e04432 | 200 | if(anno==0){ |
Susanaranjo | 2:32f3a407a8ea | 201 | pc.printf("No hay alarma 1\n"); |
Susanaranjo | 0:1c2ae7e04432 | 202 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 203 | lcd.printf("No hay alarma 1"); |
Susanaranjo | 0:1c2ae7e04432 | 204 | wait_ms(500); |
Susanaranjo | 0:1c2ae7e04432 | 205 | }else{ |
Susanaranjo | 0:1c2ae7e04432 | 206 | pc.printf("Hora de la alarma : %02d:%02d:%02d\n", hora, minutos, seg); |
Susanaranjo | 0:1c2ae7e04432 | 207 | pc.printf("Fecha de la alarma : %02d/%02d/%04d\n", fecha, mes, anno); |
Susanaranjo | 0:1c2ae7e04432 | 208 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 209 | lcd.printf("Alarma 1"); |
Susanaranjo | 2:32f3a407a8ea | 210 | wait (1); |
Susanaranjo | 0:1c2ae7e04432 | 211 | lcd.printf("%02d:%02d:%02d", hora, minutos, seg); |
Susanaranjo | 0:1c2ae7e04432 | 212 | lcd.locate(0,1); |
Susanaranjo | 0:1c2ae7e04432 | 213 | lcd.printf("%02d:%02d:%02d", fecha, mes, anno); |
Susanaranjo | 0:1c2ae7e04432 | 214 | wait(2);} |
Susanaranjo | 0:1c2ae7e04432 | 215 | |
Susanaranjo | 2:32f3a407a8ea | 216 | if(alarma2==0){ |
Susanaranjo | 2:32f3a407a8ea | 217 | pc.printf("No hay alarma 2\n"); |
Susanaranjo | 2:32f3a407a8ea | 218 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 219 | lcd.printf("No hay alarma 2"); |
Susanaranjo | 2:32f3a407a8ea | 220 | wait_ms(500); |
Susanaranjo | 2:32f3a407a8ea | 221 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 222 | pc.printf("Hora de la alarma 2 : %02d:%02d:%02d\n", hora2, minutos2, seg2); |
Susanaranjo | 2:32f3a407a8ea | 223 | pc.printf("Fecha de la alarma 2: %02d/%02d/%04d\n", fecha2, mes2, anno2); |
Susanaranjo | 2:32f3a407a8ea | 224 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 225 | lcd.printf("Alarma 2"); |
Susanaranjo | 2:32f3a407a8ea | 226 | wait (1); |
Susanaranjo | 2:32f3a407a8ea | 227 | lcd.printf("%02d:%02d:%02d", hora2, minutos2, seg2); |
Susanaranjo | 2:32f3a407a8ea | 228 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 229 | lcd.printf("%02d:%02d:%02d", fecha2, mes2, anno2); |
Susanaranjo | 2:32f3a407a8ea | 230 | wait(2);} |
Susanaranjo | 2:32f3a407a8ea | 231 | |
Susanaranjo | 2:32f3a407a8ea | 232 | |
Susanaranjo | 0:1c2ae7e04432 | 233 | goto loop1; |
Susanaranjo | 0:1c2ae7e04432 | 234 | |
Susanaranjo | 0:1c2ae7e04432 | 235 | } else { |
Susanaranjo | 0:1c2ae7e04432 | 236 | goto loop2; |
Susanaranjo | 0:1c2ae7e04432 | 237 | } |
Susanaranjo | 0:1c2ae7e04432 | 238 | |
Susanaranjo | 0:1c2ae7e04432 | 239 | |
Susanaranjo | 2:32f3a407a8ea | 240 | } |
Susanaranjo | 2:32f3a407a8ea | 241 | |
Susanaranjo | 2:32f3a407a8ea | 242 | // Configura alarma con encoder |
Susanaranjo | 2:32f3a407a8ea | 243 | else if (alarmaE==0){ |
Susanaranjo | 2:32f3a407a8ea | 244 | pc.printf("* Configurar alarma con encoder *\n"); |
Susanaranjo | 2:32f3a407a8ea | 245 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 246 | lcd.printf("Alarma con"); |
Susanaranjo | 2:32f3a407a8ea | 247 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 248 | lcd.printf("encoder"); |
Susanaranjo | 2:32f3a407a8ea | 249 | wait (1); |
Susanaranjo | 2:32f3a407a8ea | 250 | |
Susanaranjo | 2:32f3a407a8ea | 251 | |
Susanaranjo | 2:32f3a407a8ea | 252 | //Configuración fecha |
Susanaranjo | 2:32f3a407a8ea | 253 | |
Susanaranjo | 2:32f3a407a8ea | 254 | pc.printf("Fecha de la alarma:\n"); |
Susanaranjo | 2:32f3a407a8ea | 255 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 256 | lcd.printf("Fecha"); |
Susanaranjo | 2:32f3a407a8ea | 257 | |
Susanaranjo | 2:32f3a407a8ea | 258 | loop5: diferencia=encoder.getPulses()-pulsos; |
Susanaranjo | 2:32f3a407a8ea | 259 | pulsos=encoder.getPulses(); |
Susanaranjo | 2:32f3a407a8ea | 260 | if (!alarmaE){ |
Susanaranjo | 2:32f3a407a8ea | 261 | pc.printf("\n"); |
Susanaranjo | 2:32f3a407a8ea | 262 | pc.printf("Mes de la alarma:\n"); |
Susanaranjo | 2:32f3a407a8ea | 263 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 264 | lcd.printf("Mes"); |
Susanaranjo | 2:32f3a407a8ea | 265 | diferencia=0; |
Susanaranjo | 2:32f3a407a8ea | 266 | pulsos=0; |
Susanaranjo | 2:32f3a407a8ea | 267 | wait(1); |
Susanaranjo | 2:32f3a407a8ea | 268 | goto loop6; |
Susanaranjo | 2:32f3a407a8ea | 269 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 270 | if (diferencia==0){ |
Susanaranjo | 2:32f3a407a8ea | 271 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 272 | goto loop5; |
Susanaranjo | 2:32f3a407a8ea | 273 | }else if (diferencia+fecha2>=31){ |
Susanaranjo | 2:32f3a407a8ea | 274 | fecha2=31; |
Susanaranjo | 2:32f3a407a8ea | 275 | pc.printf("%02d\n", fecha2); |
Susanaranjo | 2:32f3a407a8ea | 276 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 277 | lcd.printf("%02d",fecha2); |
Susanaranjo | 2:32f3a407a8ea | 278 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 279 | goto loop5; |
Susanaranjo | 2:32f3a407a8ea | 280 | }else if(diferencia+fecha2<1) { |
Susanaranjo | 2:32f3a407a8ea | 281 | fecha2=1; |
Susanaranjo | 2:32f3a407a8ea | 282 | pc.printf("%02d\n", fecha2); |
Susanaranjo | 2:32f3a407a8ea | 283 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 284 | lcd.printf("%02d",fecha2); |
Susanaranjo | 2:32f3a407a8ea | 285 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 286 | goto loop5; |
Susanaranjo | 2:32f3a407a8ea | 287 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 288 | fecha2+=diferencia; |
Susanaranjo | 2:32f3a407a8ea | 289 | pc.printf("%02d\n", fecha2); |
Susanaranjo | 2:32f3a407a8ea | 290 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 291 | lcd.printf("%02d",fecha2); |
Susanaranjo | 2:32f3a407a8ea | 292 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 293 | goto loop5; |
Susanaranjo | 2:32f3a407a8ea | 294 | }} |
Susanaranjo | 2:32f3a407a8ea | 295 | |
Susanaranjo | 2:32f3a407a8ea | 296 | |
Susanaranjo | 2:32f3a407a8ea | 297 | |
Susanaranjo | 2:32f3a407a8ea | 298 | //Configuración mes |
Susanaranjo | 2:32f3a407a8ea | 299 | |
Susanaranjo | 2:32f3a407a8ea | 300 | |
Susanaranjo | 2:32f3a407a8ea | 301 | loop6: diferencia=encoder.getPulses()-pulsos; |
Susanaranjo | 2:32f3a407a8ea | 302 | pulsos=encoder.getPulses(); |
Susanaranjo | 2:32f3a407a8ea | 303 | if (!alarmaE){ |
Susanaranjo | 2:32f3a407a8ea | 304 | pc.printf("\n"); |
Susanaranjo | 2:32f3a407a8ea | 305 | pc.printf("Anno de la alarma:\n"); |
Susanaranjo | 2:32f3a407a8ea | 306 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 307 | lcd.printf("Anno"); |
Susanaranjo | 2:32f3a407a8ea | 308 | diferencia=0; |
Susanaranjo | 2:32f3a407a8ea | 309 | pulsos=0; |
Susanaranjo | 2:32f3a407a8ea | 310 | wait(1); |
Susanaranjo | 2:32f3a407a8ea | 311 | goto loop7; |
Susanaranjo | 2:32f3a407a8ea | 312 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 313 | if (diferencia==0){ |
Susanaranjo | 2:32f3a407a8ea | 314 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 315 | goto loop6; |
Susanaranjo | 2:32f3a407a8ea | 316 | }else if (diferencia+mes2>=12){ |
Susanaranjo | 2:32f3a407a8ea | 317 | mes2=12; |
Susanaranjo | 2:32f3a407a8ea | 318 | pc.printf("%02d\n", mes2); |
Susanaranjo | 2:32f3a407a8ea | 319 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 320 | lcd.printf("%02d",mes2); |
Susanaranjo | 2:32f3a407a8ea | 321 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 322 | goto loop6; |
Susanaranjo | 2:32f3a407a8ea | 323 | }else if(diferencia+mes2<1) { |
Susanaranjo | 2:32f3a407a8ea | 324 | mes2=1; |
Susanaranjo | 2:32f3a407a8ea | 325 | pc.printf("%02d\n", mes2); |
Susanaranjo | 2:32f3a407a8ea | 326 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 327 | lcd.printf("%02d",mes2); |
Susanaranjo | 2:32f3a407a8ea | 328 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 329 | goto loop6; |
Susanaranjo | 2:32f3a407a8ea | 330 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 331 | mes2+=diferencia; |
Susanaranjo | 2:32f3a407a8ea | 332 | pc.printf("%02d\n", mes2); |
Susanaranjo | 2:32f3a407a8ea | 333 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 334 | lcd.printf("%02d",mes2); |
Susanaranjo | 2:32f3a407a8ea | 335 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 336 | goto loop6 ; |
Susanaranjo | 2:32f3a407a8ea | 337 | }} |
Susanaranjo | 2:32f3a407a8ea | 338 | |
Susanaranjo | 2:32f3a407a8ea | 339 | |
Susanaranjo | 2:32f3a407a8ea | 340 | |
Susanaranjo | 2:32f3a407a8ea | 341 | //Configuración año |
Susanaranjo | 2:32f3a407a8ea | 342 | loop7: diferencia=encoder.getPulses()-pulsos; |
Susanaranjo | 2:32f3a407a8ea | 343 | pulsos=encoder.getPulses(); |
Susanaranjo | 2:32f3a407a8ea | 344 | if (!alarmaE){ |
Susanaranjo | 2:32f3a407a8ea | 345 | pc.printf("\n"); |
Susanaranjo | 2:32f3a407a8ea | 346 | pc.printf("Hora de la alarma:\n"); |
Susanaranjo | 2:32f3a407a8ea | 347 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 348 | lcd.printf("Hora"); |
Susanaranjo | 2:32f3a407a8ea | 349 | diferencia=0; |
Susanaranjo | 2:32f3a407a8ea | 350 | pulsos=0; |
Susanaranjo | 2:32f3a407a8ea | 351 | wait(1); |
Susanaranjo | 2:32f3a407a8ea | 352 | goto loop8; |
Susanaranjo | 2:32f3a407a8ea | 353 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 354 | if (diferencia==0){ |
Susanaranjo | 2:32f3a407a8ea | 355 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 356 | goto loop7; |
Susanaranjo | 2:32f3a407a8ea | 357 | }else if (diferencia+anno2>=2255){ |
Susanaranjo | 2:32f3a407a8ea | 358 | anno2=2255; |
Susanaranjo | 2:32f3a407a8ea | 359 | pc.printf("%04d\n", anno2); |
Susanaranjo | 2:32f3a407a8ea | 360 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 361 | lcd.printf("%04d", anno2); |
Susanaranjo | 2:32f3a407a8ea | 362 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 363 | goto loop7; |
Susanaranjo | 2:32f3a407a8ea | 364 | }else if(diferencia+anno2<2000) { |
Susanaranjo | 2:32f3a407a8ea | 365 | anno2=2000; |
Susanaranjo | 2:32f3a407a8ea | 366 | pc.printf("%04d\n", anno2); |
Susanaranjo | 2:32f3a407a8ea | 367 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 368 | lcd.printf("%04d",anno2); |
Susanaranjo | 2:32f3a407a8ea | 369 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 370 | goto loop7; |
Susanaranjo | 2:32f3a407a8ea | 371 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 372 | anno2+=diferencia; |
Susanaranjo | 2:32f3a407a8ea | 373 | pc.printf("%04d\n", anno2); |
Susanaranjo | 2:32f3a407a8ea | 374 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 375 | lcd.printf("%04d",anno2); |
Susanaranjo | 2:32f3a407a8ea | 376 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 377 | goto loop7 ; |
Susanaranjo | 2:32f3a407a8ea | 378 | }} |
Susanaranjo | 2:32f3a407a8ea | 379 | |
Susanaranjo | 2:32f3a407a8ea | 380 | |
Susanaranjo | 2:32f3a407a8ea | 381 | //Configuración hora |
Susanaranjo | 2:32f3a407a8ea | 382 | |
Susanaranjo | 2:32f3a407a8ea | 383 | |
Susanaranjo | 2:32f3a407a8ea | 384 | loop8: diferencia=encoder.getPulses()-pulsos; |
Susanaranjo | 2:32f3a407a8ea | 385 | pulsos=encoder.getPulses(); |
Susanaranjo | 2:32f3a407a8ea | 386 | if (!alarmaE){ |
Susanaranjo | 2:32f3a407a8ea | 387 | pc.printf("\n"); |
Susanaranjo | 2:32f3a407a8ea | 388 | pc.printf("Minutos de la alarma:\n"); |
Susanaranjo | 2:32f3a407a8ea | 389 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 390 | lcd.printf("Minutos"); |
Susanaranjo | 2:32f3a407a8ea | 391 | diferencia=0; |
Susanaranjo | 2:32f3a407a8ea | 392 | pulsos=0; |
Susanaranjo | 2:32f3a407a8ea | 393 | wait(1); |
Susanaranjo | 2:32f3a407a8ea | 394 | goto loop9; |
Susanaranjo | 2:32f3a407a8ea | 395 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 396 | if (diferencia==0){ |
Susanaranjo | 2:32f3a407a8ea | 397 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 398 | goto loop8; |
Susanaranjo | 2:32f3a407a8ea | 399 | }else if (diferencia+hora2>=23){ |
Susanaranjo | 2:32f3a407a8ea | 400 | hora2=23; |
Susanaranjo | 2:32f3a407a8ea | 401 | pc.printf("%02d\n", hora2); |
Susanaranjo | 2:32f3a407a8ea | 402 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 403 | lcd.printf("%02d", hora2); |
Susanaranjo | 2:32f3a407a8ea | 404 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 405 | goto loop8; |
Susanaranjo | 2:32f3a407a8ea | 406 | }else if(diferencia+hora2<0) { |
Susanaranjo | 2:32f3a407a8ea | 407 | hora2=0; |
Susanaranjo | 2:32f3a407a8ea | 408 | pc.printf("%02d\n", hora2); |
Susanaranjo | 2:32f3a407a8ea | 409 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 410 | lcd.printf("%02d",hora2); |
Susanaranjo | 2:32f3a407a8ea | 411 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 412 | goto loop8; |
Susanaranjo | 2:32f3a407a8ea | 413 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 414 | hora2+=diferencia; |
Susanaranjo | 2:32f3a407a8ea | 415 | pc.printf("%02d\n", hora2); |
Susanaranjo | 2:32f3a407a8ea | 416 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 417 | lcd.printf("%02d",hora2); |
Susanaranjo | 2:32f3a407a8ea | 418 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 419 | goto loop8 ; |
Susanaranjo | 2:32f3a407a8ea | 420 | }} |
Susanaranjo | 2:32f3a407a8ea | 421 | |
Susanaranjo | 2:32f3a407a8ea | 422 | //Configuración minutos |
Susanaranjo | 2:32f3a407a8ea | 423 | loop9: diferencia=encoder.getPulses()-pulsos; |
Susanaranjo | 2:32f3a407a8ea | 424 | pulsos=encoder.getPulses(); |
Susanaranjo | 2:32f3a407a8ea | 425 | if (!alarmaE){ |
Susanaranjo | 2:32f3a407a8ea | 426 | pc.printf("\n"); |
Susanaranjo | 2:32f3a407a8ea | 427 | pc.printf("Segundos de la alarma:\n"); |
Susanaranjo | 2:32f3a407a8ea | 428 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 429 | lcd.printf("Segundos"); |
Susanaranjo | 2:32f3a407a8ea | 430 | diferencia=0; |
Susanaranjo | 2:32f3a407a8ea | 431 | pulsos=0; |
Susanaranjo | 2:32f3a407a8ea | 432 | wait(1); |
Susanaranjo | 2:32f3a407a8ea | 433 | goto loop10; |
Susanaranjo | 2:32f3a407a8ea | 434 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 435 | if (diferencia==0){ |
Susanaranjo | 2:32f3a407a8ea | 436 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 437 | goto loop9; |
Susanaranjo | 2:32f3a407a8ea | 438 | }else if (diferencia+minutos2>=59){ |
Susanaranjo | 2:32f3a407a8ea | 439 | minutos2=59; |
Susanaranjo | 2:32f3a407a8ea | 440 | pc.printf("%02d\n", minutos2); |
Susanaranjo | 2:32f3a407a8ea | 441 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 442 | lcd.printf("%02d", minutos2); |
Susanaranjo | 2:32f3a407a8ea | 443 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 444 | goto loop9; |
Susanaranjo | 2:32f3a407a8ea | 445 | }else if(diferencia+minutos2<0) { |
Susanaranjo | 2:32f3a407a8ea | 446 | minutos2=0; |
Susanaranjo | 2:32f3a407a8ea | 447 | pc.printf("%02d\n", minutos2); |
Susanaranjo | 2:32f3a407a8ea | 448 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 449 | lcd.printf("%02d",minutos2); |
Susanaranjo | 2:32f3a407a8ea | 450 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 451 | goto loop9; |
Susanaranjo | 2:32f3a407a8ea | 452 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 453 | minutos2+=diferencia; |
Susanaranjo | 2:32f3a407a8ea | 454 | pc.printf("%02d\n", minutos2); |
Susanaranjo | 2:32f3a407a8ea | 455 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 456 | lcd.printf("%02d",minutos2); |
Susanaranjo | 2:32f3a407a8ea | 457 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 458 | goto loop9 ; |
Susanaranjo | 2:32f3a407a8ea | 459 | }} |
Susanaranjo | 2:32f3a407a8ea | 460 | |
Susanaranjo | 2:32f3a407a8ea | 461 | //Configuración segundos |
Susanaranjo | 2:32f3a407a8ea | 462 | |
Susanaranjo | 2:32f3a407a8ea | 463 | loop10: diferencia=encoder.getPulses()-pulsos; |
Susanaranjo | 2:32f3a407a8ea | 464 | pulsos=encoder.getPulses(); |
Susanaranjo | 2:32f3a407a8ea | 465 | if (!alarmaE){ |
Susanaranjo | 2:32f3a407a8ea | 466 | pc.printf("\n"); |
Susanaranjo | 2:32f3a407a8ea | 467 | pc.printf("* Fin de la configuracion *\n"); |
Susanaranjo | 2:32f3a407a8ea | 468 | lcd.cls(); |
Susanaranjo | 2:32f3a407a8ea | 469 | lcd.printf("Fin de la configuracion"); |
Susanaranjo | 2:32f3a407a8ea | 470 | diferencia=0; |
Susanaranjo | 2:32f3a407a8ea | 471 | pulsos=0; |
Susanaranjo | 2:32f3a407a8ea | 472 | alarma2=1; |
Susanaranjo | 2:32f3a407a8ea | 473 | wait(1); |
Susanaranjo | 2:32f3a407a8ea | 474 | goto loop1; |
Susanaranjo | 2:32f3a407a8ea | 475 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 476 | if (diferencia==0){ |
Susanaranjo | 2:32f3a407a8ea | 477 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 478 | goto loop10; |
Susanaranjo | 2:32f3a407a8ea | 479 | }else if (diferencia+seg2>=59){ |
Susanaranjo | 2:32f3a407a8ea | 480 | seg2=59; |
Susanaranjo | 2:32f3a407a8ea | 481 | pc.printf("%02d\n", seg2); |
Susanaranjo | 2:32f3a407a8ea | 482 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 483 | lcd.printf("%02d", seg2); |
Susanaranjo | 2:32f3a407a8ea | 484 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 485 | goto loop10; |
Susanaranjo | 2:32f3a407a8ea | 486 | }else if(diferencia+seg2<0) { |
Susanaranjo | 2:32f3a407a8ea | 487 | seg2=0; |
Susanaranjo | 2:32f3a407a8ea | 488 | pc.printf("%02d\n", seg2); |
Susanaranjo | 2:32f3a407a8ea | 489 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 490 | lcd.printf("%02d",seg2); |
Susanaranjo | 2:32f3a407a8ea | 491 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 492 | goto loop10; |
Susanaranjo | 2:32f3a407a8ea | 493 | }else{ |
Susanaranjo | 2:32f3a407a8ea | 494 | seg2+=diferencia; |
Susanaranjo | 2:32f3a407a8ea | 495 | pc.printf("%02d\n", seg2); |
Susanaranjo | 2:32f3a407a8ea | 496 | lcd.locate(0,1); |
Susanaranjo | 2:32f3a407a8ea | 497 | lcd.printf("%02d",seg2); |
Susanaranjo | 2:32f3a407a8ea | 498 | wait(0.1); |
Susanaranjo | 2:32f3a407a8ea | 499 | goto loop10 ; |
Susanaranjo | 2:32f3a407a8ea | 500 | }} |
Susanaranjo | 2:32f3a407a8ea | 501 | |
Susanaranjo | 2:32f3a407a8ea | 502 | |
Susanaranjo | 2:32f3a407a8ea | 503 | }else { |
Susanaranjo | 0:1c2ae7e04432 | 504 | //Actualizo la hora y la fecha |
Susanaranjo | 0:1c2ae7e04432 | 505 | lcd.cls(); |
Susanaranjo | 0:1c2ae7e04432 | 506 | lcd.locate(0,0); |
Susanaranjo | 0:1c2ae7e04432 | 507 | lcd.printf("%02d:%02d:%02d", tm.hour, tm.min, tm.sec); |
Susanaranjo | 0:1c2ae7e04432 | 508 | lcd.locate(0,1); |
Susanaranjo | 0:1c2ae7e04432 | 509 | lcd.printf("%s/%02d/%02d/%4d", rtc.weekdayToString(tm.wday), tm.date, tm.mon, tm.year); |
Susanaranjo | 0:1c2ae7e04432 | 510 | wait_ms(200); |
Susanaranjo | 0:1c2ae7e04432 | 511 | goto loop1; |
Susanaranjo | 2:32f3a407a8ea | 512 | }//else |
Susanaranjo | 0:1c2ae7e04432 | 513 | } |
Susanaranjo | 0:1c2ae7e04432 | 514 | |
Susanaranjo | 0:1c2ae7e04432 | 515 | |
Susanaranjo | 0:1c2ae7e04432 | 516 | |
Susanaranjo | 2:32f3a407a8ea | 517 | }// while (1) |
Susanaranjo | 2:32f3a407a8ea | 518 | }// main |