ejemplo de reloj despertador con FRDMKL25Z, usa un encoder y un LCD se instala parlante y tiene modo snozze (fastidio)

Dependencies:   Debounced QEI RTC-DS1307 TextLCD mbed

Fork of Tarea5_Reloj_alarma by Julian Palacio

Committer:
tony63
Date:
Wed Sep 28 06:48:39 2016 +0000
Revision:
1:0639f31dd59f
Parent:
0:c2ed510ee88d
ejemplo de reloj despertador con FRDMKL25Z, usa un encoder y un LCD se instala parlante y tiene modo snozze (fastidio)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jepalacioh 0:c2ed510ee88d 1 #include "mbed.h"
Jepalacioh 0:c2ed510ee88d 2 #include "DebouncedIn.h"
Jepalacioh 0:c2ed510ee88d 3 #include "TextLCD.h"
Jepalacioh 0:c2ed510ee88d 4 #include "QEI.h"
Jepalacioh 0:c2ed510ee88d 5 #include "Rtc_Ds1307.h"
Jepalacioh 0:c2ed510ee88d 6
Jepalacioh 0:c2ed510ee88d 7 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
Jepalacioh 0:c2ed510ee88d 8 Rtc_Ds1307 rtc(PTE0, PTE1);
Jepalacioh 0:c2ed510ee88d 9 QEI wheel (PTA16, PTA17, NC, 48);
Jepalacioh 0:c2ed510ee88d 10
Jepalacioh 0:c2ed510ee88d 11 DebouncedIn button_enco(PTC5);
Jepalacioh 0:c2ed510ee88d 12
Jepalacioh 0:c2ed510ee88d 13 PwmOut Sonido(PTA5);
Jepalacioh 0:c2ed510ee88d 14
Jepalacioh 0:c2ed510ee88d 15 float periodo;
Jepalacioh 0:c2ed510ee88d 16 float Frecuencia=4000;
Jepalacioh 0:c2ed510ee88d 17 int C1=0x0C;
tony63 1:0639f31dd59f 18 int m;
Jepalacioh 0:c2ed510ee88d 19 int Conf=0; // 0: Alarma y 1:Reloj
Jepalacioh 0:c2ed510ee88d 20 int Lugar=0; // Definen el punto en el cual va el programa
Jepalacioh 0:c2ed510ee88d 21 int i=0;
Jepalacioh 0:c2ed510ee88d 22 int visual=0;
Jepalacioh 0:c2ed510ee88d 23 int alarma=0;
Jepalacioh 0:c2ed510ee88d 24
Jepalacioh 0:c2ed510ee88d 25 int main()
Jepalacioh 0:c2ed510ee88d 26 {
Jepalacioh 0:c2ed510ee88d 27 Rtc_Ds1307::Time_rtc tm = {};
Jepalacioh 0:c2ed510ee88d 28 Rtc_Ds1307::Time_rtc Alarm = {};
Jepalacioh 0:c2ed510ee88d 29 lcd.cls();
Jepalacioh 0:c2ed510ee88d 30 lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
Jepalacioh 0:c2ed510ee88d 31
Jepalacioh 0:c2ed510ee88d 32 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 33 lcd.printf("--Alarma --Hora");
Jepalacioh 0:c2ed510ee88d 34
Jepalacioh 0:c2ed510ee88d 35 periodo=(1/Frecuencia);
Jepalacioh 0:c2ed510ee88d 36 Sonido.period(periodo);
Jepalacioh 0:c2ed510ee88d 37
tony63 1:0639f31dd59f 38 rtc.getTime(tm); //lee el tiempo del DS1307
Jepalacioh 0:c2ed510ee88d 39
Jepalacioh 0:c2ed510ee88d 40 while(1)
Jepalacioh 0:c2ed510ee88d 41 {
Jepalacioh 0:c2ed510ee88d 42 switch (Lugar)
Jepalacioh 0:c2ed510ee88d 43 {
Jepalacioh 0:c2ed510ee88d 44 case 0:
tony63 1:0639f31dd59f 45 m=wheel.getPulses(); // m son los datos del encoder
Jepalacioh 0:c2ed510ee88d 46 if(m!=0 && Conf==0){
Jepalacioh 0:c2ed510ee88d 47 Conf=1;
Jepalacioh 0:c2ed510ee88d 48 wheel.reset();
Jepalacioh 0:c2ed510ee88d 49 m=0;
Jepalacioh 0:c2ed510ee88d 50 }
Jepalacioh 0:c2ed510ee88d 51
Jepalacioh 0:c2ed510ee88d 52 if(m!=0 && Conf==1){
Jepalacioh 0:c2ed510ee88d 53 Conf=0;
Jepalacioh 0:c2ed510ee88d 54 wheel.reset();
Jepalacioh 0:c2ed510ee88d 55 m=0;
Jepalacioh 0:c2ed510ee88d 56 }
Jepalacioh 0:c2ed510ee88d 57
Jepalacioh 0:c2ed510ee88d 58 if(Conf==0){
Jepalacioh 0:c2ed510ee88d 59
Jepalacioh 0:c2ed510ee88d 60 lcd.locate(11,0);
Jepalacioh 0:c2ed510ee88d 61 lcd.printf("-");
Jepalacioh 0:c2ed510ee88d 62 lcd.locate(1,0);
Jepalacioh 0:c2ed510ee88d 63 lcd.printf(">");
Jepalacioh 0:c2ed510ee88d 64 lcd.locate(0,1);
Jepalacioh 0:c2ed510ee88d 65 wait(0.1);
Jepalacioh 0:c2ed510ee88d 66
Jepalacioh 0:c2ed510ee88d 67 }
Jepalacioh 0:c2ed510ee88d 68
Jepalacioh 0:c2ed510ee88d 69 if(Conf==1){
Jepalacioh 0:c2ed510ee88d 70
Jepalacioh 0:c2ed510ee88d 71 lcd.locate(1,0);
Jepalacioh 0:c2ed510ee88d 72 lcd.printf("-");
Jepalacioh 0:c2ed510ee88d 73 lcd.locate(11,0);
Jepalacioh 0:c2ed510ee88d 74 lcd.printf(">");
Jepalacioh 0:c2ed510ee88d 75 lcd.locate(0,1);
Jepalacioh 0:c2ed510ee88d 76 wait(0.1);
Jepalacioh 0:c2ed510ee88d 77 }
Jepalacioh 0:c2ed510ee88d 78
tony63 1:0639f31dd59f 79 if (button_enco.falling()){ //si se pulsa boton encoder
Jepalacioh 0:c2ed510ee88d 80 Lugar++;
Jepalacioh 0:c2ed510ee88d 81 m=0;
Jepalacioh 0:c2ed510ee88d 82 }
Jepalacioh 0:c2ed510ee88d 83
Jepalacioh 0:c2ed510ee88d 84 break;
Jepalacioh 0:c2ed510ee88d 85
Jepalacioh 0:c2ed510ee88d 86 case 1:
Jepalacioh 0:c2ed510ee88d 87 switch(i)
Jepalacioh 0:c2ed510ee88d 88 {
Jepalacioh 0:c2ed510ee88d 89 case 0:
Jepalacioh 0:c2ed510ee88d 90
Jepalacioh 0:c2ed510ee88d 91
Jepalacioh 0:c2ed510ee88d 92 if(Conf==0)
Jepalacioh 0:c2ed510ee88d 93 {
Jepalacioh 0:c2ed510ee88d 94 lcd.cls();
Jepalacioh 0:c2ed510ee88d 95 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 96 lcd.printf("Config. Alarma ");
Jepalacioh 0:c2ed510ee88d 97 wait(1);
Jepalacioh 0:c2ed510ee88d 98 i++;
Jepalacioh 0:c2ed510ee88d 99 m=0;
Jepalacioh 0:c2ed510ee88d 100 lcd.cls();
Jepalacioh 0:c2ed510ee88d 101 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 102 lcd.printf("Dia: ");
Jepalacioh 0:c2ed510ee88d 103 tm.date=1;
Jepalacioh 0:c2ed510ee88d 104 }
Jepalacioh 0:c2ed510ee88d 105
Jepalacioh 0:c2ed510ee88d 106 if(Conf==1)
Jepalacioh 0:c2ed510ee88d 107 {
Jepalacioh 0:c2ed510ee88d 108 lcd.cls();
Jepalacioh 0:c2ed510ee88d 109 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 110 lcd.printf("Config. hora ");
Jepalacioh 0:c2ed510ee88d 111 wait(1);
Jepalacioh 0:c2ed510ee88d 112 i++;
Jepalacioh 0:c2ed510ee88d 113 m=0;
Jepalacioh 0:c2ed510ee88d 114 lcd.cls();
Jepalacioh 0:c2ed510ee88d 115 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 116 lcd.printf("Dia: ");
tony63 1:0639f31dd59f 117
Jepalacioh 0:c2ed510ee88d 118 }
Jepalacioh 0:c2ed510ee88d 119
Jepalacioh 0:c2ed510ee88d 120 break;
Jepalacioh 0:c2ed510ee88d 121
Jepalacioh 0:c2ed510ee88d 122 case 1:
Jepalacioh 0:c2ed510ee88d 123 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 124 if (m!=0)
Jepalacioh 0:c2ed510ee88d 125 {
Jepalacioh 0:c2ed510ee88d 126 tm.date=tm.date+m;
Jepalacioh 0:c2ed510ee88d 127 if(tm.date>31)
Jepalacioh 0:c2ed510ee88d 128 {
Jepalacioh 0:c2ed510ee88d 129 tm.date=31;
Jepalacioh 0:c2ed510ee88d 130 }
Jepalacioh 0:c2ed510ee88d 131 if(tm.date<1)
Jepalacioh 0:c2ed510ee88d 132 {
Jepalacioh 0:c2ed510ee88d 133 tm.date=1;
Jepalacioh 0:c2ed510ee88d 134 }
Jepalacioh 0:c2ed510ee88d 135
Jepalacioh 0:c2ed510ee88d 136 wheel.reset();
Jepalacioh 0:c2ed510ee88d 137 m=0;
Jepalacioh 0:c2ed510ee88d 138 }
Jepalacioh 0:c2ed510ee88d 139 lcd.locate(5,0);
Jepalacioh 0:c2ed510ee88d 140 lcd.printf("%02d",tm.date);
Jepalacioh 0:c2ed510ee88d 141
Jepalacioh 0:c2ed510ee88d 142 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 143 {
Jepalacioh 0:c2ed510ee88d 144 i++;
Jepalacioh 0:c2ed510ee88d 145 m=0;
Jepalacioh 0:c2ed510ee88d 146 lcd.cls();
Jepalacioh 0:c2ed510ee88d 147 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 148 lcd.printf("Mes: ");
Jepalacioh 0:c2ed510ee88d 149 //tm.mon=1;
Jepalacioh 0:c2ed510ee88d 150 }
Jepalacioh 0:c2ed510ee88d 151
Jepalacioh 0:c2ed510ee88d 152 break;
Jepalacioh 0:c2ed510ee88d 153
Jepalacioh 0:c2ed510ee88d 154 case 2:
Jepalacioh 0:c2ed510ee88d 155 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 156 if (m!=0)
Jepalacioh 0:c2ed510ee88d 157 {
Jepalacioh 0:c2ed510ee88d 158 tm.mon=tm.mon+m;
Jepalacioh 0:c2ed510ee88d 159 if(tm.mon>12)
Jepalacioh 0:c2ed510ee88d 160 {
Jepalacioh 0:c2ed510ee88d 161 tm.mon=12;
Jepalacioh 0:c2ed510ee88d 162 }
Jepalacioh 0:c2ed510ee88d 163 if(tm.mon<1)
Jepalacioh 0:c2ed510ee88d 164 {
Jepalacioh 0:c2ed510ee88d 165 tm.mon=1;
Jepalacioh 0:c2ed510ee88d 166 }
Jepalacioh 0:c2ed510ee88d 167
Jepalacioh 0:c2ed510ee88d 168 wheel.reset();
Jepalacioh 0:c2ed510ee88d 169 m=0;
Jepalacioh 0:c2ed510ee88d 170 }
Jepalacioh 0:c2ed510ee88d 171 lcd.locate(5,0);
Jepalacioh 0:c2ed510ee88d 172 lcd.printf("%02d",tm.mon);
Jepalacioh 0:c2ed510ee88d 173
Jepalacioh 0:c2ed510ee88d 174 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 175 {
Jepalacioh 0:c2ed510ee88d 176 i++;
Jepalacioh 0:c2ed510ee88d 177 m=0;
Jepalacioh 0:c2ed510ee88d 178 lcd.cls();
Jepalacioh 0:c2ed510ee88d 179 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 180 lcd.printf("Year: ");
tony63 1:0639f31dd59f 181
Jepalacioh 0:c2ed510ee88d 182 }
Jepalacioh 0:c2ed510ee88d 183
Jepalacioh 0:c2ed510ee88d 184 break;
Jepalacioh 0:c2ed510ee88d 185
Jepalacioh 0:c2ed510ee88d 186 case 3:
Jepalacioh 0:c2ed510ee88d 187 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 188 if (m!=0)
Jepalacioh 0:c2ed510ee88d 189 {
Jepalacioh 0:c2ed510ee88d 190 tm.year=tm.year+m;
Jepalacioh 0:c2ed510ee88d 191
Jepalacioh 0:c2ed510ee88d 192 if(tm.year<2000)
Jepalacioh 0:c2ed510ee88d 193 {
Jepalacioh 0:c2ed510ee88d 194 tm.year=2000;
Jepalacioh 0:c2ed510ee88d 195 }
Jepalacioh 0:c2ed510ee88d 196
Jepalacioh 0:c2ed510ee88d 197 wheel.reset();
Jepalacioh 0:c2ed510ee88d 198 m=0;
Jepalacioh 0:c2ed510ee88d 199 }
Jepalacioh 0:c2ed510ee88d 200 lcd.locate(6,0);
Jepalacioh 0:c2ed510ee88d 201 lcd.printf("%02d",tm.year);
Jepalacioh 0:c2ed510ee88d 202
Jepalacioh 0:c2ed510ee88d 203 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 204 {
Jepalacioh 0:c2ed510ee88d 205 i++;
Jepalacioh 0:c2ed510ee88d 206 m=0;
Jepalacioh 0:c2ed510ee88d 207 lcd.cls();
Jepalacioh 0:c2ed510ee88d 208 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 209 lcd.printf("Hora: ");
tony63 1:0639f31dd59f 210
Jepalacioh 0:c2ed510ee88d 211 }
Jepalacioh 0:c2ed510ee88d 212
Jepalacioh 0:c2ed510ee88d 213 break;
Jepalacioh 0:c2ed510ee88d 214
Jepalacioh 0:c2ed510ee88d 215 case 4:
Jepalacioh 0:c2ed510ee88d 216 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 217
Jepalacioh 0:c2ed510ee88d 218 if (m!=0)
Jepalacioh 0:c2ed510ee88d 219 {
Jepalacioh 0:c2ed510ee88d 220 tm.hour=tm.hour + m;
Jepalacioh 0:c2ed510ee88d 221 if(tm.hour>23)
Jepalacioh 0:c2ed510ee88d 222 {
Jepalacioh 0:c2ed510ee88d 223 tm.hour=23;
Jepalacioh 0:c2ed510ee88d 224 }
Jepalacioh 0:c2ed510ee88d 225 if(tm.hour<0)
Jepalacioh 0:c2ed510ee88d 226 {
Jepalacioh 0:c2ed510ee88d 227 tm.hour=0;
Jepalacioh 0:c2ed510ee88d 228 }
Jepalacioh 0:c2ed510ee88d 229
Jepalacioh 0:c2ed510ee88d 230 wheel.reset();
Jepalacioh 0:c2ed510ee88d 231 m=0;
Jepalacioh 0:c2ed510ee88d 232 }
Jepalacioh 0:c2ed510ee88d 233 lcd.locate(6,0);
Jepalacioh 0:c2ed510ee88d 234 lcd.printf("%02d",tm.hour);
Jepalacioh 0:c2ed510ee88d 235
Jepalacioh 0:c2ed510ee88d 236 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 237 {
Jepalacioh 0:c2ed510ee88d 238 i++;
Jepalacioh 0:c2ed510ee88d 239 m=0;
Jepalacioh 0:c2ed510ee88d 240 lcd.cls();
Jepalacioh 0:c2ed510ee88d 241 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 242 lcd.printf("Minuto: ");
Jepalacioh 0:c2ed510ee88d 243 //tm.min=0;
Jepalacioh 0:c2ed510ee88d 244 }
Jepalacioh 0:c2ed510ee88d 245
Jepalacioh 0:c2ed510ee88d 246 break;
Jepalacioh 0:c2ed510ee88d 247
Jepalacioh 0:c2ed510ee88d 248 case 5:
Jepalacioh 0:c2ed510ee88d 249 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 250 if (m!=0)
Jepalacioh 0:c2ed510ee88d 251 {
Jepalacioh 0:c2ed510ee88d 252 tm.min=tm.min+m;
Jepalacioh 0:c2ed510ee88d 253 if(tm.min>59)
Jepalacioh 0:c2ed510ee88d 254 {
Jepalacioh 0:c2ed510ee88d 255 tm.min=59;
Jepalacioh 0:c2ed510ee88d 256 }
Jepalacioh 0:c2ed510ee88d 257 if(tm.min<0)
Jepalacioh 0:c2ed510ee88d 258 {
Jepalacioh 0:c2ed510ee88d 259 tm.min=0;
Jepalacioh 0:c2ed510ee88d 260 }
Jepalacioh 0:c2ed510ee88d 261
Jepalacioh 0:c2ed510ee88d 262 wheel.reset();
Jepalacioh 0:c2ed510ee88d 263 m=0;
Jepalacioh 0:c2ed510ee88d 264 }
Jepalacioh 0:c2ed510ee88d 265 lcd.locate(8,0);
Jepalacioh 0:c2ed510ee88d 266 lcd.printf("%02d",tm.min);
Jepalacioh 0:c2ed510ee88d 267
Jepalacioh 0:c2ed510ee88d 268 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 269 {
Jepalacioh 0:c2ed510ee88d 270 i++;
Jepalacioh 0:c2ed510ee88d 271 m=0;
Jepalacioh 0:c2ed510ee88d 272 lcd.cls();
Jepalacioh 0:c2ed510ee88d 273 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 274 lcd.printf("Segundo: ");
Jepalacioh 0:c2ed510ee88d 275 //tm.sec=0;
Jepalacioh 0:c2ed510ee88d 276 }
Jepalacioh 0:c2ed510ee88d 277
Jepalacioh 0:c2ed510ee88d 278 break;
Jepalacioh 0:c2ed510ee88d 279
Jepalacioh 0:c2ed510ee88d 280
Jepalacioh 0:c2ed510ee88d 281 case 6:
Jepalacioh 0:c2ed510ee88d 282 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 283 if (m!=0)
Jepalacioh 0:c2ed510ee88d 284 {
Jepalacioh 0:c2ed510ee88d 285 tm.sec=tm.sec+m;
Jepalacioh 0:c2ed510ee88d 286 if(tm.sec>59)
Jepalacioh 0:c2ed510ee88d 287 {
Jepalacioh 0:c2ed510ee88d 288 tm.sec=59;
Jepalacioh 0:c2ed510ee88d 289 }
Jepalacioh 0:c2ed510ee88d 290 if(tm.sec<0)
Jepalacioh 0:c2ed510ee88d 291 {
Jepalacioh 0:c2ed510ee88d 292 tm.sec=0;
Jepalacioh 0:c2ed510ee88d 293 }
Jepalacioh 0:c2ed510ee88d 294
Jepalacioh 0:c2ed510ee88d 295 wheel.reset();
Jepalacioh 0:c2ed510ee88d 296 m=0;
Jepalacioh 0:c2ed510ee88d 297 }
Jepalacioh 0:c2ed510ee88d 298 lcd.locate(9,0);
Jepalacioh 0:c2ed510ee88d 299 lcd.printf("%02d",tm.sec);
Jepalacioh 0:c2ed510ee88d 300
Jepalacioh 0:c2ed510ee88d 301 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 302 {
Jepalacioh 0:c2ed510ee88d 303 ///////////////////
Jepalacioh 0:c2ed510ee88d 304 if(Conf==0)
Jepalacioh 0:c2ed510ee88d 305 {
Jepalacioh 0:c2ed510ee88d 306 Alarm=tm;
Jepalacioh 0:c2ed510ee88d 307 lcd.cls();
Jepalacioh 0:c2ed510ee88d 308 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 309 lcd.printf("Alarma config. ");
Jepalacioh 0:c2ed510ee88d 310 wait(1);
Jepalacioh 0:c2ed510ee88d 311 i=0;
Jepalacioh 0:c2ed510ee88d 312 m=0;
Jepalacioh 0:c2ed510ee88d 313 Lugar++;
Jepalacioh 0:c2ed510ee88d 314 lcd.cls();
Jepalacioh 0:c2ed510ee88d 315
Jepalacioh 0:c2ed510ee88d 316 }
Jepalacioh 0:c2ed510ee88d 317
Jepalacioh 0:c2ed510ee88d 318 if(Conf==1)
Jepalacioh 0:c2ed510ee88d 319 {
Jepalacioh 0:c2ed510ee88d 320 rtc.setTime(tm, false, false);
Jepalacioh 0:c2ed510ee88d 321 rtc.startClock();
Jepalacioh 0:c2ed510ee88d 322 lcd.cls();
Jepalacioh 0:c2ed510ee88d 323 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 324 lcd.printf("Hora Config. ");
Jepalacioh 0:c2ed510ee88d 325 wait(1);
Jepalacioh 0:c2ed510ee88d 326 i=0;
Jepalacioh 0:c2ed510ee88d 327 m=0;
Jepalacioh 0:c2ed510ee88d 328 Lugar=0;
Jepalacioh 0:c2ed510ee88d 329 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 330 lcd.printf("--Alarma --Hora");
Jepalacioh 0:c2ed510ee88d 331 }
Jepalacioh 0:c2ed510ee88d 332
Jepalacioh 0:c2ed510ee88d 333 ///////////////////
Jepalacioh 0:c2ed510ee88d 334 }
Jepalacioh 0:c2ed510ee88d 335
Jepalacioh 0:c2ed510ee88d 336 break;
Jepalacioh 0:c2ed510ee88d 337
Jepalacioh 0:c2ed510ee88d 338 }
Jepalacioh 0:c2ed510ee88d 339 break;
Jepalacioh 0:c2ed510ee88d 340
Jepalacioh 0:c2ed510ee88d 341 case 2:
Jepalacioh 0:c2ed510ee88d 342
Jepalacioh 0:c2ed510ee88d 343 rtc.getTime(tm);
Jepalacioh 0:c2ed510ee88d 344
Jepalacioh 0:c2ed510ee88d 345 if(visual==0)
Jepalacioh 0:c2ed510ee88d 346 {
Jepalacioh 0:c2ed510ee88d 347
Jepalacioh 0:c2ed510ee88d 348 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 349 lcd.printf("Hora: ");
Jepalacioh 0:c2ed510ee88d 350 lcd.locate(8,0);
Jepalacioh 0:c2ed510ee88d 351 lcd.printf("%02d:",tm.hour);
Jepalacioh 0:c2ed510ee88d 352 lcd.printf("%02d:",tm.min);
Jepalacioh 0:c2ed510ee88d 353 lcd.printf("%02d",tm.sec);
Jepalacioh 0:c2ed510ee88d 354
Jepalacioh 0:c2ed510ee88d 355 lcd.locate(0,1);
Jepalacioh 0:c2ed510ee88d 356 lcd.printf("%02d/",tm.mon);
Jepalacioh 0:c2ed510ee88d 357 lcd.printf("%02d/",tm.date);
Jepalacioh 0:c2ed510ee88d 358 lcd.printf("%02d",tm.year);
Jepalacioh 0:c2ed510ee88d 359 wait(0.1);
Jepalacioh 0:c2ed510ee88d 360 //////////
Jepalacioh 0:c2ed510ee88d 361 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 362 if(m!=0)
Jepalacioh 0:c2ed510ee88d 363 {
Jepalacioh 0:c2ed510ee88d 364 visual=1;
Jepalacioh 0:c2ed510ee88d 365 wheel.reset();
Jepalacioh 0:c2ed510ee88d 366 m=0;
Jepalacioh 0:c2ed510ee88d 367 }
Jepalacioh 0:c2ed510ee88d 368
Jepalacioh 0:c2ed510ee88d 369 //////
Jepalacioh 0:c2ed510ee88d 370
Jepalacioh 0:c2ed510ee88d 371 }
Jepalacioh 0:c2ed510ee88d 372
Jepalacioh 0:c2ed510ee88d 373 if(visual==1)
Jepalacioh 0:c2ed510ee88d 374 {
Jepalacioh 0:c2ed510ee88d 375 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 376 lcd.printf("Alarma: ");
Jepalacioh 0:c2ed510ee88d 377 lcd.locate(8,0);
Jepalacioh 0:c2ed510ee88d 378 lcd.printf("%02d:",Alarm.hour);
Jepalacioh 0:c2ed510ee88d 379 lcd.printf("%02d:",Alarm.min);
Jepalacioh 0:c2ed510ee88d 380 lcd.printf("%02d",Alarm.sec);
Jepalacioh 0:c2ed510ee88d 381
Jepalacioh 0:c2ed510ee88d 382
Jepalacioh 0:c2ed510ee88d 383 lcd.locate(0,1);
Jepalacioh 0:c2ed510ee88d 384 lcd.printf("%02d/",Alarm.mon);
Jepalacioh 0:c2ed510ee88d 385 lcd.printf("%02d/",Alarm.date);
Jepalacioh 0:c2ed510ee88d 386 lcd.printf("%02d",Alarm.year);
Jepalacioh 0:c2ed510ee88d 387 wait(0.1);
Jepalacioh 0:c2ed510ee88d 388 ////
Jepalacioh 0:c2ed510ee88d 389 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 390 if(m!=0)
Jepalacioh 0:c2ed510ee88d 391 {
Jepalacioh 0:c2ed510ee88d 392 visual=0;
Jepalacioh 0:c2ed510ee88d 393 wheel.reset();
Jepalacioh 0:c2ed510ee88d 394 m=0;
Jepalacioh 0:c2ed510ee88d 395 }
Jepalacioh 0:c2ed510ee88d 396
Jepalacioh 0:c2ed510ee88d 397 ////
Jepalacioh 0:c2ed510ee88d 398 }
Jepalacioh 0:c2ed510ee88d 399
Jepalacioh 0:c2ed510ee88d 400 if( (tm.date==Alarm.date)&&(tm.mon==Alarm.mon)&&(tm.year==Alarm.year)&&(tm.hour==Alarm.hour)&&(tm.min==Alarm.min)&&(tm.sec==Alarm.sec) )
Jepalacioh 0:c2ed510ee88d 401 {
Jepalacioh 0:c2ed510ee88d 402 Lugar++;
Jepalacioh 0:c2ed510ee88d 403 lcd.cls();
Jepalacioh 0:c2ed510ee88d 404 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 405 lcd.printf("Alarma Activa!!!");
Jepalacioh 0:c2ed510ee88d 406 wait(1);
Jepalacioh 0:c2ed510ee88d 407 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 408 lcd.printf("->Desactivar ");
Jepalacioh 0:c2ed510ee88d 409 lcd.locate(0,1);
Jepalacioh 0:c2ed510ee88d 410 lcd.printf("--Aplazar ");
Jepalacioh 0:c2ed510ee88d 411 m=0;
Jepalacioh 0:c2ed510ee88d 412 }
Jepalacioh 0:c2ed510ee88d 413
Jepalacioh 0:c2ed510ee88d 414 break;
Jepalacioh 0:c2ed510ee88d 415
Jepalacioh 0:c2ed510ee88d 416 case 3:
Jepalacioh 0:c2ed510ee88d 417
Jepalacioh 0:c2ed510ee88d 418 if(alarma==0)
Jepalacioh 0:c2ed510ee88d 419 {
Jepalacioh 0:c2ed510ee88d 420 Sonido.write(0.5);
Jepalacioh 0:c2ed510ee88d 421 wait(0.2);
Jepalacioh 0:c2ed510ee88d 422 Sonido.write(0);
Jepalacioh 0:c2ed510ee88d 423 wait(0.2);
Jepalacioh 0:c2ed510ee88d 424 Sonido.write(0.5);
Jepalacioh 0:c2ed510ee88d 425 wait(0.2);
Jepalacioh 0:c2ed510ee88d 426 Sonido.write(0);
Jepalacioh 0:c2ed510ee88d 427 wait(0.2);
Jepalacioh 0:c2ed510ee88d 428
Jepalacioh 0:c2ed510ee88d 429 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 430 if(m!=0)
Jepalacioh 0:c2ed510ee88d 431 {
Jepalacioh 0:c2ed510ee88d 432 alarma=1;
Jepalacioh 0:c2ed510ee88d 433 m=0;
Jepalacioh 0:c2ed510ee88d 434 wheel.reset();
Jepalacioh 0:c2ed510ee88d 435
Jepalacioh 0:c2ed510ee88d 436 lcd.locate(1,0);
Jepalacioh 0:c2ed510ee88d 437 lcd.printf("-");
Jepalacioh 0:c2ed510ee88d 438 lcd.locate(1,1);
Jepalacioh 0:c2ed510ee88d 439 lcd.printf(">");
Jepalacioh 0:c2ed510ee88d 440 }
Jepalacioh 0:c2ed510ee88d 441 }
Jepalacioh 0:c2ed510ee88d 442
Jepalacioh 0:c2ed510ee88d 443 ///////////////////
Jepalacioh 0:c2ed510ee88d 444
Jepalacioh 0:c2ed510ee88d 445 if(alarma==1)
Jepalacioh 0:c2ed510ee88d 446 {
Jepalacioh 0:c2ed510ee88d 447 Sonido.write(0.5);
Jepalacioh 0:c2ed510ee88d 448 wait(0.2);
Jepalacioh 0:c2ed510ee88d 449 Sonido.write(0);
Jepalacioh 0:c2ed510ee88d 450 wait(0.2);
Jepalacioh 0:c2ed510ee88d 451 Sonido.write(0.5);
Jepalacioh 0:c2ed510ee88d 452 wait(0.2);
Jepalacioh 0:c2ed510ee88d 453 Sonido.write(0);
Jepalacioh 0:c2ed510ee88d 454 wait(0.2);
Jepalacioh 0:c2ed510ee88d 455
Jepalacioh 0:c2ed510ee88d 456 m=wheel.getPulses();
Jepalacioh 0:c2ed510ee88d 457 if(m!=0)
Jepalacioh 0:c2ed510ee88d 458 {
Jepalacioh 0:c2ed510ee88d 459 alarma=0;
Jepalacioh 0:c2ed510ee88d 460 m=0;
Jepalacioh 0:c2ed510ee88d 461 wheel.reset();
Jepalacioh 0:c2ed510ee88d 462
Jepalacioh 0:c2ed510ee88d 463 lcd.locate(1,0);
Jepalacioh 0:c2ed510ee88d 464 lcd.printf(">");
Jepalacioh 0:c2ed510ee88d 465 lcd.locate(1,1);
Jepalacioh 0:c2ed510ee88d 466 lcd.printf("-");
Jepalacioh 0:c2ed510ee88d 467 }
Jepalacioh 0:c2ed510ee88d 468 }
Jepalacioh 0:c2ed510ee88d 469
Jepalacioh 0:c2ed510ee88d 470 if (button_enco.falling())
Jepalacioh 0:c2ed510ee88d 471 {
Jepalacioh 0:c2ed510ee88d 472 if(alarma==0)
Jepalacioh 0:c2ed510ee88d 473 {
Jepalacioh 0:c2ed510ee88d 474 Lugar=0;
Jepalacioh 0:c2ed510ee88d 475 wheel.reset();
Jepalacioh 0:c2ed510ee88d 476 m=0;
Jepalacioh 0:c2ed510ee88d 477 Sonido.write(0);
Jepalacioh 0:c2ed510ee88d 478 lcd.cls();
Jepalacioh 0:c2ed510ee88d 479 lcd.locate(0,0);
Jepalacioh 0:c2ed510ee88d 480 lcd.printf("--Alarma --Hora");
Jepalacioh 0:c2ed510ee88d 481
Jepalacioh 0:c2ed510ee88d 482 }
Jepalacioh 0:c2ed510ee88d 483 if(alarma==1)
Jepalacioh 0:c2ed510ee88d 484 {
Jepalacioh 0:c2ed510ee88d 485 Lugar=2;
Jepalacioh 0:c2ed510ee88d 486 rtc.getTime(tm);
Jepalacioh 0:c2ed510ee88d 487 if(tm.min!=58)
Jepalacioh 0:c2ed510ee88d 488 {
Jepalacioh 0:c2ed510ee88d 489 Alarm.min=tm.min+1;
Jepalacioh 0:c2ed510ee88d 490 }
Jepalacioh 0:c2ed510ee88d 491 if(tm.min==59)
Jepalacioh 0:c2ed510ee88d 492 {
Jepalacioh 0:c2ed510ee88d 493 Alarm.min=0;
Jepalacioh 0:c2ed510ee88d 494 Alarm.hour=tm.hour+1;
Jepalacioh 0:c2ed510ee88d 495 }
Jepalacioh 0:c2ed510ee88d 496 Alarm.sec=tm.sec;
Jepalacioh 0:c2ed510ee88d 497 lcd.cls();
Jepalacioh 0:c2ed510ee88d 498 alarma=0;
Jepalacioh 0:c2ed510ee88d 499
Jepalacioh 0:c2ed510ee88d 500 }
Jepalacioh 0:c2ed510ee88d 501
Jepalacioh 0:c2ed510ee88d 502 }
Jepalacioh 0:c2ed510ee88d 503
Jepalacioh 0:c2ed510ee88d 504
Jepalacioh 0:c2ed510ee88d 505 break;
Jepalacioh 0:c2ed510ee88d 506 }
Jepalacioh 0:c2ed510ee88d 507 }
Jepalacioh 0:c2ed510ee88d 508 }