Control PID para horno de reflujo con seguimiento de consigna

Dependencies:   Debounced Pulse1 QEI RTC-DS1307 TextLCD mbed

Fork of Tarea3_procesadores_Ds1307 by Camilo Londoño

Tarea 4 procesadores 2018-1

Juan Camilo Londoño Julieta Serrano Escalante

PID para horno de reflujo conseguimiento de consigna

/media/uploads/jclondonol/4.jpg

Committer:
Jepalacioh
Date:
Tue May 13 18:42:02 2014 +0000
Revision:
0:c2ed510ee88d
Child:
1:0639f31dd59f
Reloj- alarma modulo 1307 configurado por medio de un encoder

Who changed what in which revision?

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