Tarea5-Versión1. Reloj con alarma, Usando el integrado DS1307
Dependencies: DS1307 DebouncedIn TextLCD mbed
Fork of Tarea5-V1 by
main.cpp@1:67f3f2439829, 2014-06-18 (annotated)
- Committer:
- juniorACA
- Date:
- Wed Jun 18 17:42:52 2014 +0000
- Revision:
- 1:67f3f2439829
- Parent:
- 0:b6bd9c7c76f4
Tarea 5-V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
juniorACA | 0:b6bd9c7c76f4 | 1 | #include "ds1307.h" |
juniorACA | 0:b6bd9c7c76f4 | 2 | #include "TextLCD.h" |
juniorACA | 0:b6bd9c7c76f4 | 3 | #include "mbed.h" |
juniorACA | 0:b6bd9c7c76f4 | 4 | #include "DebouncedIn.h" |
juniorACA | 1:67f3f2439829 | 5 | Serial pc(USBTX, USBRX); |
juniorACA | 0:b6bd9c7c76f4 | 6 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); //Pines de conexión Modulo LCD |
juniorACA | 1:67f3f2439829 | 7 | DS1307 my1307(PTE0,PTE1); |
juniorACA | 0:b6bd9c7c76f4 | 8 | DebouncedIn p1(PTC12); |
juniorACA | 0:b6bd9c7c76f4 | 9 | DebouncedIn p2(PTC13); |
juniorACA | 0:b6bd9c7c76f4 | 10 | DebouncedIn p3(PTC16); |
juniorACA | 0:b6bd9c7c76f4 | 11 | DebouncedIn p4(PTC17); |
juniorACA | 0:b6bd9c7c76f4 | 12 | int cont=1; |
juniorACA | 0:b6bd9c7c76f4 | 13 | int cont2 = 0; |
juniorACA | 0:b6bd9c7c76f4 | 14 | int hours1; |
juniorACA | 0:b6bd9c7c76f4 | 15 | int min1=-1; |
juniorACA | 0:b6bd9c7c76f4 | 16 | int sec1=0; |
juniorACA | 0:b6bd9c7c76f4 | 17 | int column; |
juniorACA | 0:b6bd9c7c76f4 | 18 | int fila; |
juniorACA | 1:67f3f2439829 | 19 | int C2=0x18; |
juniorACA | 1:67f3f2439829 | 20 | int C3=0x1A; |
juniorACA | 1:67f3f2439829 | 21 | int C4=0x0C; |
juniorACA | 0:b6bd9c7c76f4 | 22 | int C1=0x0F; |
juniorACA | 0:b6bd9c7c76f4 | 23 | |
juniorACA | 0:b6bd9c7c76f4 | 24 | float Dd=10; |
juniorACA | 0:b6bd9c7c76f4 | 25 | float pp=30; |
juniorACA | 0:b6bd9c7c76f4 | 26 | float Fi; |
juniorACA | 0:b6bd9c7c76f4 | 27 | |
juniorACA | 0:b6bd9c7c76f4 | 28 | PwmOut sonido(PTA12); |
juniorACA | 0:b6bd9c7c76f4 | 29 | DigitalOut led1(LED1); |
juniorACA | 1:67f3f2439829 | 30 | |
juniorACA | 0:b6bd9c7c76f4 | 31 | |
juniorACA | 1:67f3f2439829 | 32 | bool k = false; |
juniorACA | 1:67f3f2439829 | 33 | bool on = false; |
juniorACA | 0:b6bd9c7c76f4 | 34 | bool apagar = false; |
juniorACA | 0:b6bd9c7c76f4 | 35 | int sec = 30; |
juniorACA | 0:b6bd9c7c76f4 | 36 | int min = 01; |
juniorACA | 0:b6bd9c7c76f4 | 37 | int hours = 01; |
juniorACA | 0:b6bd9c7c76f4 | 38 | int day = 2; |
juniorACA | 0:b6bd9c7c76f4 | 39 | int date = 12; |
juniorACA | 0:b6bd9c7c76f4 | 40 | int month = 5; |
juniorACA | 0:b6bd9c7c76f4 | 41 | int year = 14; |
juniorACA | 0:b6bd9c7c76f4 | 42 | int loop = 10; |
juniorACA | 0:b6bd9c7c76f4 | 43 | |
juniorACA | 0:b6bd9c7c76f4 | 44 | |
juniorACA | 0:b6bd9c7c76f4 | 45 | void test_rw(int test) { |
juniorACA | 0:b6bd9c7c76f4 | 46 | if (test == 0) pc.printf("Last R/W operation passed!\n\r"); |
juniorACA | 0:b6bd9c7c76f4 | 47 | else pc.printf("Last R/W operation failed!\n\r");} |
juniorACA | 0:b6bd9c7c76f4 | 48 | |
juniorACA | 0:b6bd9c7c76f4 | 49 | |
juniorACA | 0:b6bd9c7c76f4 | 50 | int main() { |
juniorACA | 0:b6bd9c7c76f4 | 51 | |
juniorACA | 0:b6bd9c7c76f4 | 52 | test_rw(my1307.settime( sec, min, hours, day, date, month, year)); // Set the time on the DS1307 |
juniorACA | 0:b6bd9c7c76f4 | 53 | |
juniorACA | 0:b6bd9c7c76f4 | 54 | |
juniorACA | 0:b6bd9c7c76f4 | 55 | while (loop>0){ // Loop continously |
juniorACA | 0:b6bd9c7c76f4 | 56 | test_rw(my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year)); |
juniorACA | 0:b6bd9c7c76f4 | 57 | lcd.locate(4,0); // Print and refresh data on line 2 of the LCD display |
juniorACA | 0:b6bd9c7c76f4 | 58 | lcd.printf("%.2D",hours); |
juniorACA | 0:b6bd9c7c76f4 | 59 | lcd.printf(":%.2D",min); |
juniorACA | 0:b6bd9c7c76f4 | 60 | lcd.printf(":%.2D",sec); |
juniorACA | 0:b6bd9c7c76f4 | 61 | lcd.locate(4,1); |
juniorACA | 0:b6bd9c7c76f4 | 62 | lcd.printf("%.2D",month); |
juniorACA | 0:b6bd9c7c76f4 | 63 | lcd.printf("-%.2D",date); |
juniorACA | 0:b6bd9c7c76f4 | 64 | lcd.printf("-%.2D",year); |
juniorACA | 0:b6bd9c7c76f4 | 65 | |
juniorACA | 0:b6bd9c7c76f4 | 66 | |
juniorACA | 1:67f3f2439829 | 67 | // Al Presionar el Pulsadfor 1 |
juniorACA | 0:b6bd9c7c76f4 | 68 | if(p1.falling()){ //Configurar Hora |
juniorACA | 0:b6bd9c7c76f4 | 69 | |
juniorACA | 0:b6bd9c7c76f4 | 70 | if(k==true & apagar==false){ //Stop Alarm, recuerda agregar mensaje de pausa |
juniorACA | 0:b6bd9c7c76f4 | 71 | k =false; |
juniorACA | 0:b6bd9c7c76f4 | 72 | wait(1); |
juniorACA | 0:b6bd9c7c76f4 | 73 | if(p1==0){ |
juniorACA | 0:b6bd9c7c76f4 | 74 | apagar = true; |
juniorACA | 0:b6bd9c7c76f4 | 75 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 76 | lcd.printf("Alarma Desactivada"); |
juniorACA | 0:b6bd9c7c76f4 | 77 | wait(1); |
juniorACA | 0:b6bd9c7c76f4 | 78 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 79 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 80 | lcd.locate(0,1); |
juniorACA | 0:b6bd9c7c76f4 | 81 | lcd.printf("Alarma Desactivada"); |
juniorACA | 0:b6bd9c7c76f4 | 82 | wait(1); |
juniorACA | 0:b6bd9c7c76f4 | 83 | lcd.locate(0,1); |
juniorACA | 0:b6bd9c7c76f4 | 84 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 85 | hours1=0; |
juniorACA | 0:b6bd9c7c76f4 | 86 | min1=0; |
juniorACA | 0:b6bd9c7c76f4 | 87 | sec1=0; |
juniorACA | 0:b6bd9c7c76f4 | 88 | }//cierro p1==0 |
juniorACA | 0:b6bd9c7c76f4 | 89 | if(apagar==false){ |
juniorACA | 0:b6bd9c7c76f4 | 90 | sec1=sec+10; |
juniorACA | 0:b6bd9c7c76f4 | 91 | if(sec1>59){ |
juniorACA | 0:b6bd9c7c76f4 | 92 | min1 = min1 +1; |
juniorACA | 0:b6bd9c7c76f4 | 93 | sec1 = sec1-60; |
juniorACA | 0:b6bd9c7c76f4 | 94 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 95 | lcd.locate(1,0); |
juniorACA | 1:67f3f2439829 | 96 | lcd.printf("Min.Alarm: %.2d",min1); |
juniorACA | 0:b6bd9c7c76f4 | 97 | wait(0.5); |
juniorACA | 0:b6bd9c7c76f4 | 98 | |
juniorACA | 0:b6bd9c7c76f4 | 99 | }//cierro if sec > 59 |
juniorACA | 0:b6bd9c7c76f4 | 100 | |
juniorACA | 0:b6bd9c7c76f4 | 101 | }//cierro Apagar == false |
juniorACA | 0:b6bd9c7c76f4 | 102 | |
juniorACA | 0:b6bd9c7c76f4 | 103 | }//cierro k = true && apagar == false |
juniorACA | 0:b6bd9c7c76f4 | 104 | |
juniorACA | 0:b6bd9c7c76f4 | 105 | |
juniorACA | 0:b6bd9c7c76f4 | 106 | if(cont ==2){ |
juniorACA | 0:b6bd9c7c76f4 | 107 | ++hours; |
juniorACA | 0:b6bd9c7c76f4 | 108 | |
juniorACA | 0:b6bd9c7c76f4 | 109 | if(hours>23){//ajuste de hora |
juniorACA | 0:b6bd9c7c76f4 | 110 | hours = 0; |
juniorACA | 0:b6bd9c7c76f4 | 111 | }//Fin if hoours >23 |
juniorACA | 0:b6bd9c7c76f4 | 112 | |
juniorACA | 0:b6bd9c7c76f4 | 113 | test_rw(my1307.settime( sec, min, hours, day, date, month, year)); // Set the time on the DS1307 |
juniorACA | 0:b6bd9c7c76f4 | 114 | |
juniorACA | 0:b6bd9c7c76f4 | 115 | |
juniorACA | 0:b6bd9c7c76f4 | 116 | }//Cierro if contador ==2 |
juniorACA | 0:b6bd9c7c76f4 | 117 | |
juniorACA | 0:b6bd9c7c76f4 | 118 | if(cont == 3){ |
juniorACA | 0:b6bd9c7c76f4 | 119 | ++min; |
juniorACA | 0:b6bd9c7c76f4 | 120 | |
juniorACA | 0:b6bd9c7c76f4 | 121 | if(min>59){ //Ajuste de minutos |
juniorACA | 0:b6bd9c7c76f4 | 122 | min = 0; |
juniorACA | 0:b6bd9c7c76f4 | 123 | } //cierro if min > 59 |
juniorACA | 0:b6bd9c7c76f4 | 124 | |
juniorACA | 0:b6bd9c7c76f4 | 125 | test_rw(my1307.settime( sec, min, hours, day, date, month, year)); // Set the time on the DS1307 |
juniorACA | 0:b6bd9c7c76f4 | 126 | |
juniorACA | 0:b6bd9c7c76f4 | 127 | } //Cierro if contador ==3 |
juniorACA | 0:b6bd9c7c76f4 | 128 | |
juniorACA | 0:b6bd9c7c76f4 | 129 | if(cont == 4){//configurar mes |
juniorACA | 0:b6bd9c7c76f4 | 130 | ++month; |
juniorACA | 0:b6bd9c7c76f4 | 131 | |
juniorACA | 0:b6bd9c7c76f4 | 132 | if(month > 12){ //ajuste de meses |
juniorACA | 0:b6bd9c7c76f4 | 133 | month =1; |
juniorACA | 0:b6bd9c7c76f4 | 134 | }//cierro mont > 12 |
juniorACA | 0:b6bd9c7c76f4 | 135 | |
juniorACA | 0:b6bd9c7c76f4 | 136 | test_rw(my1307.settime( sec, min, hours, day, date, month, year)); // Set the time on the DS1307 |
juniorACA | 0:b6bd9c7c76f4 | 137 | |
juniorACA | 0:b6bd9c7c76f4 | 138 | }//cierro contador ==4 |
juniorACA | 0:b6bd9c7c76f4 | 139 | |
juniorACA | 0:b6bd9c7c76f4 | 140 | |
juniorACA | 0:b6bd9c7c76f4 | 141 | if(cont ==5){ |
juniorACA | 0:b6bd9c7c76f4 | 142 | ++date; |
juniorACA | 0:b6bd9c7c76f4 | 143 | |
juniorACA | 0:b6bd9c7c76f4 | 144 | if(month==1 || month ==3 || month == 5 || month == 7 || month ==8 || month ==10 || month ==12 ){//ajuste de 31 dias |
juniorACA | 0:b6bd9c7c76f4 | 145 | |
juniorACA | 0:b6bd9c7c76f4 | 146 | if(date > 31){ |
juniorACA | 0:b6bd9c7c76f4 | 147 | date=01; |
juniorACA | 0:b6bd9c7c76f4 | 148 | }//Cierro day >31 |
juniorACA | 0:b6bd9c7c76f4 | 149 | }//cierro condicion meses con 31 dias |
juniorACA | 0:b6bd9c7c76f4 | 150 | |
juniorACA | 0:b6bd9c7c76f4 | 151 | if( month ==4 || month == 6 || month == 9 || month ==11){//ajuste de 30 dias |
juniorACA | 0:b6bd9c7c76f4 | 152 | |
juniorACA | 0:b6bd9c7c76f4 | 153 | if(date >30){ |
juniorACA | 0:b6bd9c7c76f4 | 154 | date=01; |
juniorACA | 0:b6bd9c7c76f4 | 155 | }//Cierro day >30 |
juniorACA | 0:b6bd9c7c76f4 | 156 | }//Cierro condicion meses de 30 dias |
juniorACA | 0:b6bd9c7c76f4 | 157 | |
juniorACA | 0:b6bd9c7c76f4 | 158 | if(month==2 ){//ajuste de 28 dias |
juniorACA | 0:b6bd9c7c76f4 | 159 | |
juniorACA | 0:b6bd9c7c76f4 | 160 | if((year+2000) % 4 ==0){ //configuracion año viciesto |
juniorACA | 0:b6bd9c7c76f4 | 161 | |
juniorACA | 0:b6bd9c7c76f4 | 162 | if(date >29){ |
juniorACA | 0:b6bd9c7c76f4 | 163 | date=1; |
juniorACA | 0:b6bd9c7c76f4 | 164 | }//cierro if date> 29 |
juniorACA | 0:b6bd9c7c76f4 | 165 | |
juniorACA | 0:b6bd9c7c76f4 | 166 | }//Cierro año viciesto |
juniorACA | 0:b6bd9c7c76f4 | 167 | |
juniorACA | 0:b6bd9c7c76f4 | 168 | if((year+2000) % 4 != 0){ //configuracion año viciesto |
juniorACA | 0:b6bd9c7c76f4 | 169 | |
juniorACA | 0:b6bd9c7c76f4 | 170 | if(date >28){ |
juniorACA | 0:b6bd9c7c76f4 | 171 | date=1; |
juniorACA | 0:b6bd9c7c76f4 | 172 | }//cierro if date> 28 |
juniorACA | 0:b6bd9c7c76f4 | 173 | |
juniorACA | 0:b6bd9c7c76f4 | 174 | |
juniorACA | 0:b6bd9c7c76f4 | 175 | }//Cierro año NO viciesto |
juniorACA | 0:b6bd9c7c76f4 | 176 | |
juniorACA | 0:b6bd9c7c76f4 | 177 | |
juniorACA | 0:b6bd9c7c76f4 | 178 | }//cierro if month ==2 |
juniorACA | 0:b6bd9c7c76f4 | 179 | |
juniorACA | 0:b6bd9c7c76f4 | 180 | test_rw(my1307.settime( sec, min, hours, day, date, month, year)); // Set the time on the DS1307 |
juniorACA | 0:b6bd9c7c76f4 | 181 | |
juniorACA | 0:b6bd9c7c76f4 | 182 | }//cierro if contador ==5 |
juniorACA | 0:b6bd9c7c76f4 | 183 | |
juniorACA | 0:b6bd9c7c76f4 | 184 | if(cont == 6){ //Aumentar años |
juniorACA | 0:b6bd9c7c76f4 | 185 | ++year; |
juniorACA | 0:b6bd9c7c76f4 | 186 | test_rw(my1307.settime( sec, min, hours, day, date, month, year)); // Set the time on the DS1307 |
juniorACA | 0:b6bd9c7c76f4 | 187 | |
juniorACA | 0:b6bd9c7c76f4 | 188 | }//cierro if contador ==6 |
juniorACA | 0:b6bd9c7c76f4 | 189 | |
juniorACA | 0:b6bd9c7c76f4 | 190 | |
juniorACA | 0:b6bd9c7c76f4 | 191 | //Configuracin De Alarma |
juniorACA | 0:b6bd9c7c76f4 | 192 | if(cont2==1){ |
juniorACA | 0:b6bd9c7c76f4 | 193 | hours1++; |
juniorACA | 0:b6bd9c7c76f4 | 194 | if(hours1>23){ |
juniorACA | 0:b6bd9c7c76f4 | 195 | hours1= 0; |
juniorACA | 0:b6bd9c7c76f4 | 196 | }//Cierro hours1>23 |
juniorACA | 0:b6bd9c7c76f4 | 197 | |
juniorACA | 0:b6bd9c7c76f4 | 198 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 199 | lcd.printf("Hora.Alarma: %.2d ",hours1); |
juniorACA | 0:b6bd9c7c76f4 | 200 | wait(1); |
juniorACA | 0:b6bd9c7c76f4 | 201 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 202 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 203 | }//Cierro if cont2==1 |
juniorACA | 0:b6bd9c7c76f4 | 204 | |
juniorACA | 0:b6bd9c7c76f4 | 205 | if(cont2==2){ |
juniorACA | 0:b6bd9c7c76f4 | 206 | min1++; |
juniorACA | 0:b6bd9c7c76f4 | 207 | if(min1>59){ |
juniorACA | 0:b6bd9c7c76f4 | 208 | min1= 0; |
juniorACA | 0:b6bd9c7c76f4 | 209 | }//Cierro min1>59 |
juniorACA | 0:b6bd9c7c76f4 | 210 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 211 | lcd.printf("Min.Alarma: %.2d ",min1); |
juniorACA | 0:b6bd9c7c76f4 | 212 | wait(1); |
juniorACA | 0:b6bd9c7c76f4 | 213 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 214 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 215 | |
juniorACA | 0:b6bd9c7c76f4 | 216 | }//Cierro if cont2==1 |
juniorACA | 0:b6bd9c7c76f4 | 217 | |
juniorACA | 0:b6bd9c7c76f4 | 218 | |
juniorACA | 0:b6bd9c7c76f4 | 219 | }//Fin p1.falling |
juniorACA | 0:b6bd9c7c76f4 | 220 | |
juniorACA | 0:b6bd9c7c76f4 | 221 | //Presionar Pulsador 2 |
juniorACA | 0:b6bd9c7c76f4 | 222 | if(p2.falling()){ //Reset |
juniorACA | 0:b6bd9c7c76f4 | 223 | cont = cont+1; |
juniorACA | 0:b6bd9c7c76f4 | 224 | |
juniorACA | 0:b6bd9c7c76f4 | 225 | if(cont>0){ |
juniorACA | 0:b6bd9c7c76f4 | 226 | cont2=0;} |
juniorACA | 0:b6bd9c7c76f4 | 227 | |
juniorACA | 0:b6bd9c7c76f4 | 228 | if(cont ==1){ |
juniorACA | 0:b6bd9c7c76f4 | 229 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 230 | lcd.printf("1-Reset"); |
juniorACA | 0:b6bd9c7c76f4 | 231 | wait(2); |
juniorACA | 0:b6bd9c7c76f4 | 232 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 233 | }//cierro if cont ==1 |
juniorACA | 0:b6bd9c7c76f4 | 234 | |
juniorACA | 0:b6bd9c7c76f4 | 235 | if(cont==2){ //configuración de la Hora |
juniorACA | 0:b6bd9c7c76f4 | 236 | lcd.locate(2,0); |
juniorACA | 0:b6bd9c7c76f4 | 237 | lcd.printf("Config. hora"); |
juniorACA | 0:b6bd9c7c76f4 | 238 | wait(2); |
juniorACA | 0:b6bd9c7c76f4 | 239 | lcd.locate(2,0); |
juniorACA | 0:b6bd9c7c76f4 | 240 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 241 | }//Cierro if cont ==2 |
juniorACA | 0:b6bd9c7c76f4 | 242 | |
juniorACA | 0:b6bd9c7c76f4 | 243 | if(cont==3){ //configurar minutos |
juniorACA | 0:b6bd9c7c76f4 | 244 | lcd.locate(1,0); |
juniorACA | 0:b6bd9c7c76f4 | 245 | lcd.printf("Config. Minutos"); |
juniorACA | 0:b6bd9c7c76f4 | 246 | wait(2); |
juniorACA | 0:b6bd9c7c76f4 | 247 | lcd.locate(1,0); |
juniorACA | 0:b6bd9c7c76f4 | 248 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 249 | }//Cierro if cont ==3 |
juniorACA | 0:b6bd9c7c76f4 | 250 | |
juniorACA | 0:b6bd9c7c76f4 | 251 | if(cont ==4){ |
juniorACA | 0:b6bd9c7c76f4 | 252 | lcd.locate(2,0); |
juniorACA | 0:b6bd9c7c76f4 | 253 | lcd.printf("Config. Mes"); |
juniorACA | 0:b6bd9c7c76f4 | 254 | wait(2); |
juniorACA | 0:b6bd9c7c76f4 | 255 | lcd.locate(2,0); |
juniorACA | 0:b6bd9c7c76f4 | 256 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 257 | }//cierro if contador ==4 |
juniorACA | 0:b6bd9c7c76f4 | 258 | |
juniorACA | 0:b6bd9c7c76f4 | 259 | if(cont == 5){ |
juniorACA | 0:b6bd9c7c76f4 | 260 | lcd.locate(2,0); |
juniorACA | 0:b6bd9c7c76f4 | 261 | lcd.printf("Config. Dia"); |
juniorACA | 0:b6bd9c7c76f4 | 262 | wait(2); |
juniorACA | 0:b6bd9c7c76f4 | 263 | lcd.locate(2,0); |
juniorACA | 0:b6bd9c7c76f4 | 264 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 265 | }//Cierro if cont == 5 |
juniorACA | 0:b6bd9c7c76f4 | 266 | |
juniorACA | 0:b6bd9c7c76f4 | 267 | if(cont ==6){ |
juniorACA | 0:b6bd9c7c76f4 | 268 | lcd.locate(3,0); |
juniorACA | 0:b6bd9c7c76f4 | 269 | lcd.printf("Conf. anio"); //Se aumentan años en p1 y se disminuyen con p3 (ver p3 debajo) |
juniorACA | 0:b6bd9c7c76f4 | 270 | wait(2); |
juniorACA | 0:b6bd9c7c76f4 | 271 | lcd.locate(3,0); |
juniorACA | 0:b6bd9c7c76f4 | 272 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 273 | }//Cierro if cont ==6 |
juniorACA | 0:b6bd9c7c76f4 | 274 | |
juniorACA | 0:b6bd9c7c76f4 | 275 | if(cont>6){ //Reset Cont |
juniorACA | 0:b6bd9c7c76f4 | 276 | cont =1; |
juniorACA | 0:b6bd9c7c76f4 | 277 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 278 | lcd.printf("Conf.Establecida"); |
juniorACA | 0:b6bd9c7c76f4 | 279 | wait(2); |
juniorACA | 0:b6bd9c7c76f4 | 280 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 281 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 282 | }//Cierro cont > 6 |
juniorACA | 0:b6bd9c7c76f4 | 283 | |
juniorACA | 0:b6bd9c7c76f4 | 284 | }//Cierro if p2.falling() |
juniorACA | 0:b6bd9c7c76f4 | 285 | |
juniorACA | 0:b6bd9c7c76f4 | 286 | |
juniorACA | 0:b6bd9c7c76f4 | 287 | //Presionar Pulsador 3 |
juniorACA | 0:b6bd9c7c76f4 | 288 | if(p3.falling()){ |
juniorACA | 0:b6bd9c7c76f4 | 289 | |
juniorACA | 0:b6bd9c7c76f4 | 290 | if(cont==6){ |
juniorACA | 0:b6bd9c7c76f4 | 291 | --year; |
juniorACA | 0:b6bd9c7c76f4 | 292 | test_rw(my1307.settime( sec, min, hours, day, date, month, year)); // Set the time on the DS1307 |
juniorACA | 0:b6bd9c7c76f4 | 293 | cont2=0; |
juniorACA | 0:b6bd9c7c76f4 | 294 | |
juniorACA | 0:b6bd9c7c76f4 | 295 | }//Cierro if cont == 6 |
juniorACA | 0:b6bd9c7c76f4 | 296 | |
juniorACA | 0:b6bd9c7c76f4 | 297 | if(cont != 6){ |
juniorACA | 0:b6bd9c7c76f4 | 298 | |
juniorACA | 1:67f3f2439829 | 299 | cont=1; |
juniorACA | 0:b6bd9c7c76f4 | 300 | cont2++; |
juniorACA | 0:b6bd9c7c76f4 | 301 | |
juniorACA | 0:b6bd9c7c76f4 | 302 | if(cont2==1){ |
juniorACA | 0:b6bd9c7c76f4 | 303 | lcd.locate(1,0); |
juniorACA | 0:b6bd9c7c76f4 | 304 | lcd.printf("Hora de Alarma"); |
juniorACA | 0:b6bd9c7c76f4 | 305 | wait(1); |
juniorACA | 0:b6bd9c7c76f4 | 306 | lcd.locate(1,0); |
juniorACA | 0:b6bd9c7c76f4 | 307 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 308 | } //cierro cont2 ==1 |
juniorACA | 0:b6bd9c7c76f4 | 309 | |
juniorACA | 0:b6bd9c7c76f4 | 310 | if(cont2==2){ |
juniorACA | 0:b6bd9c7c76f4 | 311 | lcd.locate(2,0); |
juniorACA | 0:b6bd9c7c76f4 | 312 | lcd.printf("Min de Alarma"); |
juniorACA | 0:b6bd9c7c76f4 | 313 | wait(1); |
juniorACA | 0:b6bd9c7c76f4 | 314 | lcd.locate(2,0); |
juniorACA | 0:b6bd9c7c76f4 | 315 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 316 | } //cierro cont2 ==1 |
juniorACA | 0:b6bd9c7c76f4 | 317 | |
juniorACA | 0:b6bd9c7c76f4 | 318 | if(cont2>2){ |
juniorACA | 0:b6bd9c7c76f4 | 319 | cont2=0; |
juniorACA | 0:b6bd9c7c76f4 | 320 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 321 | lcd.printf(" Alarma Activa "); |
juniorACA | 0:b6bd9c7c76f4 | 322 | wait(1); |
juniorACA | 0:b6bd9c7c76f4 | 323 | lcd.locate(0,0); |
juniorACA | 0:b6bd9c7c76f4 | 324 | lcd.printf(" "); |
juniorACA | 0:b6bd9c7c76f4 | 325 | k = true; //alarma activada |
juniorACA | 0:b6bd9c7c76f4 | 326 | apagar=false; |
juniorACA | 0:b6bd9c7c76f4 | 327 | }//cierro if cont2 >2 |
juniorACA | 0:b6bd9c7c76f4 | 328 | |
juniorACA | 0:b6bd9c7c76f4 | 329 | }//Cierro cont != 6 |
juniorACA | 0:b6bd9c7c76f4 | 330 | |
juniorACA | 0:b6bd9c7c76f4 | 331 | }//cierro if p3.falling() |
juniorACA | 0:b6bd9c7c76f4 | 332 | |
juniorACA | 0:b6bd9c7c76f4 | 333 | //Activacion De Alarma |
juniorACA | 0:b6bd9c7c76f4 | 334 | if(hours == hours1 && k == true && apagar ==false){ |
juniorACA | 0:b6bd9c7c76f4 | 335 | if(min == min1){ |
juniorACA | 0:b6bd9c7c76f4 | 336 | if(sec>=sec1 && sec<=(sec1+10)){ |
juniorACA | 0:b6bd9c7c76f4 | 337 | |
juniorACA | 0:b6bd9c7c76f4 | 338 | Fi=(Dd)*100; |
juniorACA | 0:b6bd9c7c76f4 | 339 | pp=(1/Fi); |
juniorACA | 0:b6bd9c7c76f4 | 340 | sonido.period(pp); |
juniorACA | 0:b6bd9c7c76f4 | 341 | sonido.write(0.1); |
juniorACA | 0:b6bd9c7c76f4 | 342 | wait(0.1); |
juniorACA | 0:b6bd9c7c76f4 | 343 | sonido.write(0); |
juniorACA | 0:b6bd9c7c76f4 | 344 | wait(0.1); |
juniorACA | 0:b6bd9c7c76f4 | 345 | led1 =!led1; |
juniorACA | 0:b6bd9c7c76f4 | 346 | |
juniorACA | 0:b6bd9c7c76f4 | 347 | if(p4.falling()){ |
juniorACA | 0:b6bd9c7c76f4 | 348 | sonido=0.0; |
juniorACA | 0:b6bd9c7c76f4 | 349 | |
juniorACA | 1:67f3f2439829 | 350 | |
juniorACA | 0:b6bd9c7c76f4 | 351 | |
juniorACA | 0:b6bd9c7c76f4 | 352 | if(k==false){ |
juniorACA | 0:b6bd9c7c76f4 | 353 | break; |
juniorACA | 0:b6bd9c7c76f4 | 354 | }//cierro if on==false |
juniorACA | 0:b6bd9c7c76f4 | 355 | }//Cierro For |
juniorACA | 0:b6bd9c7c76f4 | 356 | |
juniorACA | 0:b6bd9c7c76f4 | 357 | }//Cierro Sec>=0 && sec <30 |
juniorACA | 0:b6bd9c7c76f4 | 358 | }//Cierro min == min1 |
juniorACA | 0:b6bd9c7c76f4 | 359 | |
juniorACA | 0:b6bd9c7c76f4 | 360 | }//cierro hours==hours1 |
juniorACA | 0:b6bd9c7c76f4 | 361 | |
juniorACA | 0:b6bd9c7c76f4 | 362 | if(sec1>0 & k==false){ //alarma encendida, reactiva k para poder iniciar nuevamente cuando el tiempo se alcance otra vez |
juniorACA | 0:b6bd9c7c76f4 | 363 | k = true; |
juniorACA | 0:b6bd9c7c76f4 | 364 | }//Cierro if sec1>0 |
juniorACA | 0:b6bd9c7c76f4 | 365 | |
juniorACA | 0:b6bd9c7c76f4 | 366 | } //Cierro While loop >0 |
juniorACA | 0:b6bd9c7c76f4 | 367 | |
juniorACA | 0:b6bd9c7c76f4 | 368 | |
juniorACA | 0:b6bd9c7c76f4 | 369 | |
juniorACA | 0:b6bd9c7c76f4 | 370 | } //Cierro Main() |