![](/media/cache/profiles/IMG-20170731-WA002223234124.jpg.50x50_q85.jpg)
Se definen 7 alarmas de forma preestablecida y luego se escogen con un control remoto.
Dependencies: Debounced Pulse1 QEI RTC-DS1307 TextLCD mbed
Fork of Reloj_alarma by
main.cpp@2:8b79efdd0127, 2018-05-23 (annotated)
- Committer:
- seccastanova
- Date:
- Wed May 23 18:40:41 2018 +0000
- Revision:
- 2:8b79efdd0127
- Parent:
- 1:0639f31dd59f
Tarea que permite configurar 7 alarmas predefinidas usando un reloj RTC1307;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seccastanova | 2:8b79efdd0127 | 1 | /* |
seccastanova | 2:8b79efdd0127 | 2 | ESTE PROGRAMA PERMITE CONFIGURAR UNA SERIE DE ALARMAS (7) PREDEFINIDAS QUE LUEGO |
seccastanova | 2:8b79efdd0127 | 3 | PODRÁN SER ESCOGIDAS CON UN CONTROL DE TELEVISOR MARCA LG CON LOS NÚMEROS DE 1 A 7 |
seccastanova | 2:8b79efdd0127 | 4 | SE USA UN RELOJ RTC 1307 Y UN RECEPTOR IRDA COMUN. |
seccastanova | 2:8b79efdd0127 | 5 | ESTA TAREA FUE DESARROLLADA POR SEBASTIÁN CAMILO CASTAÑO VANEGAS Y CARLOS MAURICIO ALZATE TORRES |
seccastanova | 2:8b79efdd0127 | 6 | PARA LA MATERIA DE PROCESADORES DE LA UNIVERSIDAD NACIONAL DE MEDELLÍN SEMESTRE I DEL AÑO 2018 |
seccastanova | 2:8b79efdd0127 | 7 | */ |
Jepalacioh | 0:c2ed510ee88d | 8 | #include "mbed.h" |
Jepalacioh | 0:c2ed510ee88d | 9 | #include "DebouncedIn.h" |
Jepalacioh | 0:c2ed510ee88d | 10 | #include "TextLCD.h" |
Jepalacioh | 0:c2ed510ee88d | 11 | #include "QEI.h" |
Jepalacioh | 0:c2ed510ee88d | 12 | #include "Rtc_Ds1307.h" |
seccastanova | 2:8b79efdd0127 | 13 | #include "string.h" |
seccastanova | 2:8b79efdd0127 | 14 | #include <Pulse1.h> |
Jepalacioh | 0:c2ed510ee88d | 15 | |
seccastanova | 2:8b79efdd0127 | 16 | PulseInOut irda(PTB0);// en este puerto se pone el sensor infrarrojo |
Jepalacioh | 0:c2ed510ee88d | 17 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 |
Jepalacioh | 0:c2ed510ee88d | 18 | Rtc_Ds1307 rtc(PTE0, PTE1); |
Jepalacioh | 0:c2ed510ee88d | 19 | QEI wheel (PTA16, PTA17, NC, 48); |
Jepalacioh | 0:c2ed510ee88d | 20 | DebouncedIn button_enco(PTC5); |
seccastanova | 2:8b79efdd0127 | 21 | DigitalOut myled(LED3); |
Jepalacioh | 0:c2ed510ee88d | 22 | |
seccastanova | 2:8b79efdd0127 | 23 | int numN[35];//cadena para almacenar todos los tiempos que conforman los bits de datos |
seccastanova | 2:8b79efdd0127 | 24 | int numP[35];//cadena para almacenar todos los tiempos que conforman los bits de datos |
seccastanova | 2:8b79efdd0127 | 25 | int numbin[35]; |
seccastanova | 2:8b79efdd0127 | 26 | int bin[35];//cadena para almacenar todos los tiempos que conforman los bits de datos |
seccastanova | 2:8b79efdd0127 | 27 | int dato; // tiempo de cada dato que se lee |
seccastanova | 2:8b79efdd0127 | 28 | int pul_low; |
seccastanova | 2:8b79efdd0127 | 29 | int i1,j1,k1,header,proL,proH; |
seccastanova | 2:8b79efdd0127 | 30 | char r; |
seccastanova | 2:8b79efdd0127 | 31 | char cadena[33]; |
seccastanova | 2:8b79efdd0127 | 32 | char uno[33]="10110100101101001101110000100011"; |
seccastanova | 2:8b79efdd0127 | 33 | char dos[33]="10110100101101000011110011000011"; |
seccastanova | 2:8b79efdd0127 | 34 | char tres[33]="10110100101101001011110001000011"; |
seccastanova | 2:8b79efdd0127 | 35 | char cuatro[33]="10110100101101000111110010000011"; |
seccastanova | 2:8b79efdd0127 | 36 | char cinco[33]="10110100101101001111110000000011"; |
seccastanova | 2:8b79efdd0127 | 37 | char seis[33]="10110100101101000000001011111101"; |
seccastanova | 2:8b79efdd0127 | 38 | char siete[33]="10110100101101001000001001111101"; |
seccastanova | 2:8b79efdd0127 | 39 | char set[33]="00100000110111110001000011101111"; |
seccastanova | 2:8b79efdd0127 | 40 | int mode=0; |
seccastanova | 2:8b79efdd0127 | 41 | int code; |
seccastanova | 2:8b79efdd0127 | 42 | int numb=32; |
seccastanova | 2:8b79efdd0127 | 43 | int s=0; |
seccastanova | 2:8b79efdd0127 | 44 | // |
Jepalacioh | 0:c2ed510ee88d | 45 | int C1=0x0C; |
tony63 | 1:0639f31dd59f | 46 | int m; |
Jepalacioh | 0:c2ed510ee88d | 47 | int Conf=0; // 0: Alarma y 1:Reloj |
Jepalacioh | 0:c2ed510ee88d | 48 | int Lugar=0; // Definen el punto en el cual va el programa |
Jepalacioh | 0:c2ed510ee88d | 49 | int i=0; |
seccastanova | 2:8b79efdd0127 | 50 | int j=1; |
seccastanova | 2:8b79efdd0127 | 51 | int IRDA=1; |
seccastanova | 2:8b79efdd0127 | 52 | int irda_en=0; |
Jepalacioh | 0:c2ed510ee88d | 53 | int visual=0; |
seccastanova | 2:8b79efdd0127 | 54 | int alarma=0; |
Jepalacioh | 0:c2ed510ee88d | 55 | int main() |
Jepalacioh | 0:c2ed510ee88d | 56 | { |
seccastanova | 2:8b79efdd0127 | 57 | myled=1; |
seccastanova | 2:8b79efdd0127 | 58 | j=1; |
seccastanova | 2:8b79efdd0127 | 59 | Rtc_Ds1307::Time_rtc tm2 = {}; |
Jepalacioh | 0:c2ed510ee88d | 60 | Rtc_Ds1307::Time_rtc tm = {}; |
seccastanova | 2:8b79efdd0127 | 61 | Rtc_Ds1307::Time_rtc Alarm[8] = {}; |
Jepalacioh | 0:c2ed510ee88d | 62 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 63 | lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD |
Jepalacioh | 0:c2ed510ee88d | 64 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 65 | lcd.printf("--Alarms --Time"); |
tony63 | 1:0639f31dd59f | 66 | rtc.getTime(tm); //lee el tiempo del DS1307 |
Jepalacioh | 0:c2ed510ee88d | 67 | |
Jepalacioh | 0:c2ed510ee88d | 68 | while(1) |
Jepalacioh | 0:c2ed510ee88d | 69 | { |
seccastanova | 2:8b79efdd0127 | 70 | |
Jepalacioh | 0:c2ed510ee88d | 71 | switch (Lugar) |
Jepalacioh | 0:c2ed510ee88d | 72 | { |
Jepalacioh | 0:c2ed510ee88d | 73 | case 0: |
tony63 | 1:0639f31dd59f | 74 | m=wheel.getPulses(); // m son los datos del encoder |
Jepalacioh | 0:c2ed510ee88d | 75 | if(m!=0 && Conf==0){ |
Jepalacioh | 0:c2ed510ee88d | 76 | Conf=1; |
Jepalacioh | 0:c2ed510ee88d | 77 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 78 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 79 | } |
Jepalacioh | 0:c2ed510ee88d | 80 | |
seccastanova | 2:8b79efdd0127 | 81 | if(m!=0 && Conf==1){ |
Jepalacioh | 0:c2ed510ee88d | 82 | Conf=0; |
Jepalacioh | 0:c2ed510ee88d | 83 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 84 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 85 | } |
Jepalacioh | 0:c2ed510ee88d | 86 | |
Jepalacioh | 0:c2ed510ee88d | 87 | if(Conf==0){ |
Jepalacioh | 0:c2ed510ee88d | 88 | |
Jepalacioh | 0:c2ed510ee88d | 89 | lcd.locate(11,0); |
Jepalacioh | 0:c2ed510ee88d | 90 | lcd.printf("-"); |
Jepalacioh | 0:c2ed510ee88d | 91 | lcd.locate(1,0); |
Jepalacioh | 0:c2ed510ee88d | 92 | lcd.printf(">"); |
Jepalacioh | 0:c2ed510ee88d | 93 | lcd.locate(0,1); |
Jepalacioh | 0:c2ed510ee88d | 94 | wait(0.1); |
Jepalacioh | 0:c2ed510ee88d | 95 | |
Jepalacioh | 0:c2ed510ee88d | 96 | } |
Jepalacioh | 0:c2ed510ee88d | 97 | |
Jepalacioh | 0:c2ed510ee88d | 98 | if(Conf==1){ |
Jepalacioh | 0:c2ed510ee88d | 99 | |
Jepalacioh | 0:c2ed510ee88d | 100 | lcd.locate(1,0); |
Jepalacioh | 0:c2ed510ee88d | 101 | lcd.printf("-"); |
Jepalacioh | 0:c2ed510ee88d | 102 | lcd.locate(11,0); |
Jepalacioh | 0:c2ed510ee88d | 103 | lcd.printf(">"); |
Jepalacioh | 0:c2ed510ee88d | 104 | lcd.locate(0,1); |
Jepalacioh | 0:c2ed510ee88d | 105 | wait(0.1); |
Jepalacioh | 0:c2ed510ee88d | 106 | } |
Jepalacioh | 0:c2ed510ee88d | 107 | |
tony63 | 1:0639f31dd59f | 108 | if (button_enco.falling()){ //si se pulsa boton encoder |
Jepalacioh | 0:c2ed510ee88d | 109 | Lugar++; |
Jepalacioh | 0:c2ed510ee88d | 110 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 111 | } |
Jepalacioh | 0:c2ed510ee88d | 112 | |
Jepalacioh | 0:c2ed510ee88d | 113 | break; |
Jepalacioh | 0:c2ed510ee88d | 114 | |
Jepalacioh | 0:c2ed510ee88d | 115 | case 1: |
Jepalacioh | 0:c2ed510ee88d | 116 | switch(i) |
Jepalacioh | 0:c2ed510ee88d | 117 | { |
seccastanova | 2:8b79efdd0127 | 118 | case 0: |
seccastanova | 2:8b79efdd0127 | 119 | if(Conf==0) // ALARMA |
Jepalacioh | 0:c2ed510ee88d | 120 | { |
Jepalacioh | 0:c2ed510ee88d | 121 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 122 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 123 | lcd.printf("Config. Alarms "); |
Jepalacioh | 0:c2ed510ee88d | 124 | wait(1); |
seccastanova | 2:8b79efdd0127 | 125 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 126 | i++; |
Jepalacioh | 0:c2ed510ee88d | 127 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 128 | lcd.printf("Day: "); |
seccastanova | 2:8b79efdd0127 | 129 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 130 | } |
Jepalacioh | 0:c2ed510ee88d | 131 | |
seccastanova | 2:8b79efdd0127 | 132 | if(Conf==1) //RELOJ |
Jepalacioh | 0:c2ed510ee88d | 133 | { |
Jepalacioh | 0:c2ed510ee88d | 134 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 135 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 136 | lcd.printf("Config. Time "); |
Jepalacioh | 0:c2ed510ee88d | 137 | wait(1); |
Jepalacioh | 0:c2ed510ee88d | 138 | i++; |
Jepalacioh | 0:c2ed510ee88d | 139 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 140 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 141 | lcd.printf("Day: "); |
seccastanova | 2:8b79efdd0127 | 142 | m=0; |
tony63 | 1:0639f31dd59f | 143 | |
Jepalacioh | 0:c2ed510ee88d | 144 | } |
Jepalacioh | 0:c2ed510ee88d | 145 | |
Jepalacioh | 0:c2ed510ee88d | 146 | break; |
Jepalacioh | 0:c2ed510ee88d | 147 | |
seccastanova | 2:8b79efdd0127 | 148 | case 1: //DAY OF WEEK |
seccastanova | 2:8b79efdd0127 | 149 | m=wheel.getPulses(); |
seccastanova | 2:8b79efdd0127 | 150 | if (m!=0) |
seccastanova | 2:8b79efdd0127 | 151 | { |
seccastanova | 2:8b79efdd0127 | 152 | tm.wday=tm.wday+m; |
seccastanova | 2:8b79efdd0127 | 153 | if(tm.wday>7) |
seccastanova | 2:8b79efdd0127 | 154 | { |
seccastanova | 2:8b79efdd0127 | 155 | tm.wday=7; |
seccastanova | 2:8b79efdd0127 | 156 | } |
seccastanova | 2:8b79efdd0127 | 157 | if(tm.wday<1) |
seccastanova | 2:8b79efdd0127 | 158 | { |
seccastanova | 2:8b79efdd0127 | 159 | tm.wday=1; |
seccastanova | 2:8b79efdd0127 | 160 | } |
seccastanova | 2:8b79efdd0127 | 161 | |
seccastanova | 2:8b79efdd0127 | 162 | wheel.reset(); |
seccastanova | 2:8b79efdd0127 | 163 | m=0; |
seccastanova | 2:8b79efdd0127 | 164 | } |
seccastanova | 2:8b79efdd0127 | 165 | |
seccastanova | 2:8b79efdd0127 | 166 | switch(tm.wday){ |
seccastanova | 2:8b79efdd0127 | 167 | case (1): |
seccastanova | 2:8b79efdd0127 | 168 | lcd.locate(5,0); |
seccastanova | 2:8b79efdd0127 | 169 | lcd.printf("Sunday "); |
seccastanova | 2:8b79efdd0127 | 170 | break; |
seccastanova | 2:8b79efdd0127 | 171 | case (2): |
seccastanova | 2:8b79efdd0127 | 172 | lcd.locate(5,0); |
seccastanova | 2:8b79efdd0127 | 173 | lcd.printf("Monday "); |
seccastanova | 2:8b79efdd0127 | 174 | break; |
seccastanova | 2:8b79efdd0127 | 175 | case (3): |
seccastanova | 2:8b79efdd0127 | 176 | lcd.locate(5,0); |
seccastanova | 2:8b79efdd0127 | 177 | lcd.printf("Tuesday "); |
seccastanova | 2:8b79efdd0127 | 178 | break; |
seccastanova | 2:8b79efdd0127 | 179 | case (4): |
seccastanova | 2:8b79efdd0127 | 180 | lcd.locate(5,0); |
seccastanova | 2:8b79efdd0127 | 181 | lcd.printf("Wednesday"); |
seccastanova | 2:8b79efdd0127 | 182 | break; |
seccastanova | 2:8b79efdd0127 | 183 | case (5): |
seccastanova | 2:8b79efdd0127 | 184 | lcd.locate(5,0); |
seccastanova | 2:8b79efdd0127 | 185 | lcd.printf("Thursday "); |
seccastanova | 2:8b79efdd0127 | 186 | break; |
seccastanova | 2:8b79efdd0127 | 187 | case (6): |
seccastanova | 2:8b79efdd0127 | 188 | lcd.locate(5,0); |
seccastanova | 2:8b79efdd0127 | 189 | lcd.printf("Friday "); |
seccastanova | 2:8b79efdd0127 | 190 | break; |
seccastanova | 2:8b79efdd0127 | 191 | case (7): |
seccastanova | 2:8b79efdd0127 | 192 | lcd.locate(5,0); |
seccastanova | 2:8b79efdd0127 | 193 | lcd.printf("Saturday "); |
seccastanova | 2:8b79efdd0127 | 194 | break; |
seccastanova | 2:8b79efdd0127 | 195 | } |
seccastanova | 2:8b79efdd0127 | 196 | |
seccastanova | 2:8b79efdd0127 | 197 | |
seccastanova | 2:8b79efdd0127 | 198 | if (button_enco.falling()) |
seccastanova | 2:8b79efdd0127 | 199 | { |
seccastanova | 2:8b79efdd0127 | 200 | switch(Conf) |
seccastanova | 2:8b79efdd0127 | 201 | { |
seccastanova | 2:8b79efdd0127 | 202 | case 0: |
seccastanova | 2:8b79efdd0127 | 203 | i=5; |
seccastanova | 2:8b79efdd0127 | 204 | m=0; |
seccastanova | 2:8b79efdd0127 | 205 | lcd.cls(); |
seccastanova | 2:8b79efdd0127 | 206 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 207 | lcd.printf("Hour: "); |
seccastanova | 2:8b79efdd0127 | 208 | m=0; |
seccastanova | 2:8b79efdd0127 | 209 | break; |
seccastanova | 2:8b79efdd0127 | 210 | case 1: |
seccastanova | 2:8b79efdd0127 | 211 | i=2; |
seccastanova | 2:8b79efdd0127 | 212 | m=0; |
seccastanova | 2:8b79efdd0127 | 213 | lcd.cls(); |
seccastanova | 2:8b79efdd0127 | 214 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 215 | lcd.printf("Day: "); |
seccastanova | 2:8b79efdd0127 | 216 | break; |
seccastanova | 2:8b79efdd0127 | 217 | } |
seccastanova | 2:8b79efdd0127 | 218 | } |
seccastanova | 2:8b79efdd0127 | 219 | |
seccastanova | 2:8b79efdd0127 | 220 | break; |
seccastanova | 2:8b79efdd0127 | 221 | case 2: // DAY OF DATE |
seccastanova | 2:8b79efdd0127 | 222 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 223 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 224 | if (m!=0) |
Jepalacioh | 0:c2ed510ee88d | 225 | { |
Jepalacioh | 0:c2ed510ee88d | 226 | tm.date=tm.date+m; |
Jepalacioh | 0:c2ed510ee88d | 227 | if(tm.date>31) |
Jepalacioh | 0:c2ed510ee88d | 228 | { |
Jepalacioh | 0:c2ed510ee88d | 229 | tm.date=31; |
Jepalacioh | 0:c2ed510ee88d | 230 | } |
Jepalacioh | 0:c2ed510ee88d | 231 | if(tm.date<1) |
Jepalacioh | 0:c2ed510ee88d | 232 | { |
Jepalacioh | 0:c2ed510ee88d | 233 | tm.date=1; |
Jepalacioh | 0:c2ed510ee88d | 234 | } |
Jepalacioh | 0:c2ed510ee88d | 235 | |
Jepalacioh | 0:c2ed510ee88d | 236 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 237 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 238 | } |
Jepalacioh | 0:c2ed510ee88d | 239 | lcd.locate(5,0); |
seccastanova | 2:8b79efdd0127 | 240 | lcd.printf("%02d ",tm.date); |
Jepalacioh | 0:c2ed510ee88d | 241 | |
Jepalacioh | 0:c2ed510ee88d | 242 | if (button_enco.falling()) |
Jepalacioh | 0:c2ed510ee88d | 243 | { |
Jepalacioh | 0:c2ed510ee88d | 244 | i++; |
Jepalacioh | 0:c2ed510ee88d | 245 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 246 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 247 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 248 | lcd.printf("Month: "); |
seccastanova | 2:8b79efdd0127 | 249 | |
Jepalacioh | 0:c2ed510ee88d | 250 | } |
Jepalacioh | 0:c2ed510ee88d | 251 | break; |
seccastanova | 2:8b79efdd0127 | 252 | case 3: // MONTH |
Jepalacioh | 0:c2ed510ee88d | 253 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 254 | if (m!=0) |
Jepalacioh | 0:c2ed510ee88d | 255 | { |
Jepalacioh | 0:c2ed510ee88d | 256 | tm.mon=tm.mon+m; |
Jepalacioh | 0:c2ed510ee88d | 257 | if(tm.mon>12) |
Jepalacioh | 0:c2ed510ee88d | 258 | { |
Jepalacioh | 0:c2ed510ee88d | 259 | tm.mon=12; |
Jepalacioh | 0:c2ed510ee88d | 260 | } |
Jepalacioh | 0:c2ed510ee88d | 261 | if(tm.mon<1) |
Jepalacioh | 0:c2ed510ee88d | 262 | { |
Jepalacioh | 0:c2ed510ee88d | 263 | tm.mon=1; |
Jepalacioh | 0:c2ed510ee88d | 264 | } |
Jepalacioh | 0:c2ed510ee88d | 265 | |
Jepalacioh | 0:c2ed510ee88d | 266 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 267 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 268 | } |
seccastanova | 2:8b79efdd0127 | 269 | lcd.locate(7,0); |
Jepalacioh | 0:c2ed510ee88d | 270 | lcd.printf("%02d",tm.mon); |
Jepalacioh | 0:c2ed510ee88d | 271 | |
Jepalacioh | 0:c2ed510ee88d | 272 | if (button_enco.falling()) |
Jepalacioh | 0:c2ed510ee88d | 273 | { |
Jepalacioh | 0:c2ed510ee88d | 274 | i++; |
Jepalacioh | 0:c2ed510ee88d | 275 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 276 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 277 | lcd.locate(0,0); |
Jepalacioh | 0:c2ed510ee88d | 278 | lcd.printf("Year: "); |
tony63 | 1:0639f31dd59f | 279 | |
Jepalacioh | 0:c2ed510ee88d | 280 | } |
Jepalacioh | 0:c2ed510ee88d | 281 | |
Jepalacioh | 0:c2ed510ee88d | 282 | break; |
Jepalacioh | 0:c2ed510ee88d | 283 | |
seccastanova | 2:8b79efdd0127 | 284 | case 4: //YEAR |
Jepalacioh | 0:c2ed510ee88d | 285 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 286 | if (m!=0) |
Jepalacioh | 0:c2ed510ee88d | 287 | { |
Jepalacioh | 0:c2ed510ee88d | 288 | tm.year=tm.year+m; |
Jepalacioh | 0:c2ed510ee88d | 289 | |
Jepalacioh | 0:c2ed510ee88d | 290 | if(tm.year<2000) |
Jepalacioh | 0:c2ed510ee88d | 291 | { |
Jepalacioh | 0:c2ed510ee88d | 292 | tm.year=2000; |
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(6,0); |
Jepalacioh | 0:c2ed510ee88d | 299 | lcd.printf("%02d",tm.year); |
Jepalacioh | 0:c2ed510ee88d | 300 | |
Jepalacioh | 0:c2ed510ee88d | 301 | if (button_enco.falling()) |
Jepalacioh | 0:c2ed510ee88d | 302 | { |
seccastanova | 2:8b79efdd0127 | 303 | i=5; |
Jepalacioh | 0:c2ed510ee88d | 304 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 305 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 306 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 307 | lcd.printf("Hour: "); |
seccastanova | 2:8b79efdd0127 | 308 | |
tony63 | 1:0639f31dd59f | 309 | |
Jepalacioh | 0:c2ed510ee88d | 310 | } |
Jepalacioh | 0:c2ed510ee88d | 311 | |
Jepalacioh | 0:c2ed510ee88d | 312 | break; |
Jepalacioh | 0:c2ed510ee88d | 313 | |
seccastanova | 2:8b79efdd0127 | 314 | case 5: //HOUR |
seccastanova | 2:8b79efdd0127 | 315 | m=0; |
seccastanova | 2:8b79efdd0127 | 316 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 317 | if (m!=0) |
Jepalacioh | 0:c2ed510ee88d | 318 | { |
seccastanova | 2:8b79efdd0127 | 319 | tm.hour+= m; |
Jepalacioh | 0:c2ed510ee88d | 320 | if(tm.hour>23) |
Jepalacioh | 0:c2ed510ee88d | 321 | { |
Jepalacioh | 0:c2ed510ee88d | 322 | tm.hour=23; |
Jepalacioh | 0:c2ed510ee88d | 323 | } |
Jepalacioh | 0:c2ed510ee88d | 324 | if(tm.hour<0) |
Jepalacioh | 0:c2ed510ee88d | 325 | { |
Jepalacioh | 0:c2ed510ee88d | 326 | tm.hour=0; |
Jepalacioh | 0:c2ed510ee88d | 327 | } |
Jepalacioh | 0:c2ed510ee88d | 328 | |
Jepalacioh | 0:c2ed510ee88d | 329 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 330 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 331 | } |
Jepalacioh | 0:c2ed510ee88d | 332 | lcd.locate(6,0); |
Jepalacioh | 0:c2ed510ee88d | 333 | lcd.printf("%02d",tm.hour); |
Jepalacioh | 0:c2ed510ee88d | 334 | |
Jepalacioh | 0:c2ed510ee88d | 335 | if (button_enco.falling()) |
Jepalacioh | 0:c2ed510ee88d | 336 | { |
seccastanova | 2:8b79efdd0127 | 337 | i=6; |
Jepalacioh | 0:c2ed510ee88d | 338 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 339 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 340 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 341 | lcd.printf("Minute: "); |
Jepalacioh | 0:c2ed510ee88d | 342 | //tm.min=0; |
Jepalacioh | 0:c2ed510ee88d | 343 | } |
Jepalacioh | 0:c2ed510ee88d | 344 | |
Jepalacioh | 0:c2ed510ee88d | 345 | break; |
Jepalacioh | 0:c2ed510ee88d | 346 | |
seccastanova | 2:8b79efdd0127 | 347 | case 6: //MINUTE |
seccastanova | 2:8b79efdd0127 | 348 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 349 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 350 | if (m!=0) |
Jepalacioh | 0:c2ed510ee88d | 351 | { |
Jepalacioh | 0:c2ed510ee88d | 352 | tm.min=tm.min+m; |
Jepalacioh | 0:c2ed510ee88d | 353 | if(tm.min>59) |
Jepalacioh | 0:c2ed510ee88d | 354 | { |
Jepalacioh | 0:c2ed510ee88d | 355 | tm.min=59; |
Jepalacioh | 0:c2ed510ee88d | 356 | } |
Jepalacioh | 0:c2ed510ee88d | 357 | if(tm.min<0) |
Jepalacioh | 0:c2ed510ee88d | 358 | { |
Jepalacioh | 0:c2ed510ee88d | 359 | tm.min=0; |
Jepalacioh | 0:c2ed510ee88d | 360 | } |
Jepalacioh | 0:c2ed510ee88d | 361 | |
Jepalacioh | 0:c2ed510ee88d | 362 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 363 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 364 | } |
Jepalacioh | 0:c2ed510ee88d | 365 | lcd.locate(8,0); |
Jepalacioh | 0:c2ed510ee88d | 366 | lcd.printf("%02d",tm.min); |
Jepalacioh | 0:c2ed510ee88d | 367 | |
Jepalacioh | 0:c2ed510ee88d | 368 | if (button_enco.falling()) |
Jepalacioh | 0:c2ed510ee88d | 369 | { |
seccastanova | 2:8b79efdd0127 | 370 | i=7; |
Jepalacioh | 0:c2ed510ee88d | 371 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 372 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 373 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 374 | lcd.printf("Second: "); |
Jepalacioh | 0:c2ed510ee88d | 375 | //tm.sec=0; |
Jepalacioh | 0:c2ed510ee88d | 376 | } |
Jepalacioh | 0:c2ed510ee88d | 377 | |
Jepalacioh | 0:c2ed510ee88d | 378 | break; |
Jepalacioh | 0:c2ed510ee88d | 379 | |
Jepalacioh | 0:c2ed510ee88d | 380 | |
seccastanova | 2:8b79efdd0127 | 381 | case 7: //SECOND |
Jepalacioh | 0:c2ed510ee88d | 382 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 383 | if (m!=0) |
Jepalacioh | 0:c2ed510ee88d | 384 | { |
Jepalacioh | 0:c2ed510ee88d | 385 | tm.sec=tm.sec+m; |
Jepalacioh | 0:c2ed510ee88d | 386 | if(tm.sec>59) |
Jepalacioh | 0:c2ed510ee88d | 387 | { |
Jepalacioh | 0:c2ed510ee88d | 388 | tm.sec=59; |
Jepalacioh | 0:c2ed510ee88d | 389 | } |
Jepalacioh | 0:c2ed510ee88d | 390 | if(tm.sec<0) |
Jepalacioh | 0:c2ed510ee88d | 391 | { |
Jepalacioh | 0:c2ed510ee88d | 392 | tm.sec=0; |
Jepalacioh | 0:c2ed510ee88d | 393 | } |
Jepalacioh | 0:c2ed510ee88d | 394 | |
Jepalacioh | 0:c2ed510ee88d | 395 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 396 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 397 | } |
seccastanova | 2:8b79efdd0127 | 398 | lcd.locate(8,0); |
Jepalacioh | 0:c2ed510ee88d | 399 | lcd.printf("%02d",tm.sec); |
Jepalacioh | 0:c2ed510ee88d | 400 | |
Jepalacioh | 0:c2ed510ee88d | 401 | if (button_enco.falling()) |
Jepalacioh | 0:c2ed510ee88d | 402 | { |
Jepalacioh | 0:c2ed510ee88d | 403 | /////////////////// |
Jepalacioh | 0:c2ed510ee88d | 404 | if(Conf==0) |
Jepalacioh | 0:c2ed510ee88d | 405 | { |
seccastanova | 2:8b79efdd0127 | 406 | Alarm[j]=tm; |
Jepalacioh | 0:c2ed510ee88d | 407 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 408 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 409 | lcd.printf("Alarm %d config. ",j); |
Jepalacioh | 0:c2ed510ee88d | 410 | wait(1); |
Jepalacioh | 0:c2ed510ee88d | 411 | i=0; |
Jepalacioh | 0:c2ed510ee88d | 412 | m=0; |
seccastanova | 2:8b79efdd0127 | 413 | if(j>=7) |
seccastanova | 2:8b79efdd0127 | 414 | { |
Jepalacioh | 0:c2ed510ee88d | 415 | Lugar++; |
seccastanova | 2:8b79efdd0127 | 416 | } |
seccastanova | 2:8b79efdd0127 | 417 | j++; |
Jepalacioh | 0:c2ed510ee88d | 418 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 419 | |
Jepalacioh | 0:c2ed510ee88d | 420 | } |
Jepalacioh | 0:c2ed510ee88d | 421 | |
Jepalacioh | 0:c2ed510ee88d | 422 | if(Conf==1) |
seccastanova | 2:8b79efdd0127 | 423 | { |
seccastanova | 2:8b79efdd0127 | 424 | rtc.setTime(tm, true, false); |
Jepalacioh | 0:c2ed510ee88d | 425 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 426 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 427 | lcd.printf("Time config. "); |
Jepalacioh | 0:c2ed510ee88d | 428 | wait(1); |
Jepalacioh | 0:c2ed510ee88d | 429 | i=0; |
Jepalacioh | 0:c2ed510ee88d | 430 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 431 | Lugar=0; |
Jepalacioh | 0:c2ed510ee88d | 432 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 433 | lcd.printf("--Alarms --Time"); |
Jepalacioh | 0:c2ed510ee88d | 434 | } |
Jepalacioh | 0:c2ed510ee88d | 435 | |
Jepalacioh | 0:c2ed510ee88d | 436 | /////////////////// |
Jepalacioh | 0:c2ed510ee88d | 437 | } |
Jepalacioh | 0:c2ed510ee88d | 438 | |
Jepalacioh | 0:c2ed510ee88d | 439 | break; |
Jepalacioh | 0:c2ed510ee88d | 440 | |
Jepalacioh | 0:c2ed510ee88d | 441 | } |
Jepalacioh | 0:c2ed510ee88d | 442 | break; |
Jepalacioh | 0:c2ed510ee88d | 443 | |
seccastanova | 2:8b79efdd0127 | 444 | case 2: // SHOW THE TIME AND ALARM AND COMPROBATE THE ALARM STATE |
seccastanova | 2:8b79efdd0127 | 445 | rtc.getTime(tm2); //READING THE RTC |
seccastanova | 2:8b79efdd0127 | 446 | |
Jepalacioh | 0:c2ed510ee88d | 447 | |
Jepalacioh | 0:c2ed510ee88d | 448 | if(visual==0) |
seccastanova | 2:8b79efdd0127 | 449 | { |
Jepalacioh | 0:c2ed510ee88d | 450 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 451 | lcd.printf("Hour: "); |
Jepalacioh | 0:c2ed510ee88d | 452 | lcd.locate(8,0); |
seccastanova | 2:8b79efdd0127 | 453 | lcd.printf("%02d:",tm2.hour); |
seccastanova | 2:8b79efdd0127 | 454 | lcd.printf("%02d:",tm2.min); |
seccastanova | 2:8b79efdd0127 | 455 | lcd.printf("%02d",tm2.sec); |
Jepalacioh | 0:c2ed510ee88d | 456 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 457 | switch(tm2.wday){ |
seccastanova | 2:8b79efdd0127 | 458 | case (1): |
seccastanova | 2:8b79efdd0127 | 459 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 460 | lcd.printf("Sun "); |
seccastanova | 2:8b79efdd0127 | 461 | break; |
seccastanova | 2:8b79efdd0127 | 462 | case (2): |
seccastanova | 2:8b79efdd0127 | 463 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 464 | lcd.printf("Mon "); |
seccastanova | 2:8b79efdd0127 | 465 | break; |
seccastanova | 2:8b79efdd0127 | 466 | case (3): |
seccastanova | 2:8b79efdd0127 | 467 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 468 | lcd.printf("Tue "); |
seccastanova | 2:8b79efdd0127 | 469 | break; |
seccastanova | 2:8b79efdd0127 | 470 | case (4): |
seccastanova | 2:8b79efdd0127 | 471 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 472 | lcd.printf("Wed "); |
seccastanova | 2:8b79efdd0127 | 473 | break; |
seccastanova | 2:8b79efdd0127 | 474 | case (5): |
seccastanova | 2:8b79efdd0127 | 475 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 476 | lcd.printf("Thu "); |
seccastanova | 2:8b79efdd0127 | 477 | break; |
seccastanova | 2:8b79efdd0127 | 478 | case (6): |
seccastanova | 2:8b79efdd0127 | 479 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 480 | lcd.printf("Fri "); |
seccastanova | 2:8b79efdd0127 | 481 | break; |
seccastanova | 2:8b79efdd0127 | 482 | case (7): |
seccastanova | 2:8b79efdd0127 | 483 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 484 | lcd.printf("Sat "); |
seccastanova | 2:8b79efdd0127 | 485 | break; |
seccastanova | 2:8b79efdd0127 | 486 | } |
seccastanova | 2:8b79efdd0127 | 487 | lcd.locate(6,1); |
seccastanova | 2:8b79efdd0127 | 488 | lcd.printf("%02d/",tm2.date); |
seccastanova | 2:8b79efdd0127 | 489 | lcd.printf("%02d/",tm2.mon); |
seccastanova | 2:8b79efdd0127 | 490 | lcd.printf("%02d",tm2.year); |
Jepalacioh | 0:c2ed510ee88d | 491 | wait(0.1); |
Jepalacioh | 0:c2ed510ee88d | 492 | ////////// |
Jepalacioh | 0:c2ed510ee88d | 493 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 494 | if(m!=0) |
Jepalacioh | 0:c2ed510ee88d | 495 | { |
Jepalacioh | 0:c2ed510ee88d | 496 | visual=1; |
Jepalacioh | 0:c2ed510ee88d | 497 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 498 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 499 | } |
Jepalacioh | 0:c2ed510ee88d | 500 | } |
Jepalacioh | 0:c2ed510ee88d | 501 | |
Jepalacioh | 0:c2ed510ee88d | 502 | if(visual==1) |
Jepalacioh | 0:c2ed510ee88d | 503 | { |
seccastanova | 2:8b79efdd0127 | 504 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 505 | lcd.printf(" "); |
Jepalacioh | 0:c2ed510ee88d | 506 | lcd.locate(8,0); |
seccastanova | 2:8b79efdd0127 | 507 | lcd.printf("%02d:",Alarm[IRDA].hour); |
seccastanova | 2:8b79efdd0127 | 508 | lcd.printf("%02d:",Alarm[IRDA].min); |
seccastanova | 2:8b79efdd0127 | 509 | lcd.printf("%02d",Alarm[IRDA].sec); |
Jepalacioh | 0:c2ed510ee88d | 510 | |
seccastanova | 2:8b79efdd0127 | 511 | switch(Alarm[IRDA].wday){ |
seccastanova | 2:8b79efdd0127 | 512 | case (1): |
seccastanova | 2:8b79efdd0127 | 513 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 514 | lcd.printf("Sun "); |
seccastanova | 2:8b79efdd0127 | 515 | break; |
seccastanova | 2:8b79efdd0127 | 516 | case (2): |
seccastanova | 2:8b79efdd0127 | 517 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 518 | lcd.printf("Mon "); |
seccastanova | 2:8b79efdd0127 | 519 | break; |
seccastanova | 2:8b79efdd0127 | 520 | case (3): |
seccastanova | 2:8b79efdd0127 | 521 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 522 | lcd.printf("Tue "); |
seccastanova | 2:8b79efdd0127 | 523 | break; |
seccastanova | 2:8b79efdd0127 | 524 | case (4): |
seccastanova | 2:8b79efdd0127 | 525 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 526 | lcd.printf("Wed "); |
seccastanova | 2:8b79efdd0127 | 527 | break; |
seccastanova | 2:8b79efdd0127 | 528 | case (5): |
seccastanova | 2:8b79efdd0127 | 529 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 530 | lcd.printf("Thu "); |
seccastanova | 2:8b79efdd0127 | 531 | break; |
seccastanova | 2:8b79efdd0127 | 532 | case (6): |
seccastanova | 2:8b79efdd0127 | 533 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 534 | lcd.printf("Fri "); |
seccastanova | 2:8b79efdd0127 | 535 | break; |
seccastanova | 2:8b79efdd0127 | 536 | case (7): |
seccastanova | 2:8b79efdd0127 | 537 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 538 | lcd.printf("Sat "); |
seccastanova | 2:8b79efdd0127 | 539 | break; |
seccastanova | 2:8b79efdd0127 | 540 | } |
seccastanova | 2:8b79efdd0127 | 541 | lcd.locate(5,1); |
seccastanova | 2:8b79efdd0127 | 542 | lcd.printf("Alarm %d Set",IRDA); |
Jepalacioh | 0:c2ed510ee88d | 543 | wait(0.1); |
Jepalacioh | 0:c2ed510ee88d | 544 | //// |
Jepalacioh | 0:c2ed510ee88d | 545 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 546 | if(m!=0) |
Jepalacioh | 0:c2ed510ee88d | 547 | { |
Jepalacioh | 0:c2ed510ee88d | 548 | visual=0; |
Jepalacioh | 0:c2ed510ee88d | 549 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 550 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 551 | } |
Jepalacioh | 0:c2ed510ee88d | 552 | } |
seccastanova | 2:8b79efdd0127 | 553 | /////////////////////////////////// ALARM COMPROBATION ///////////////////////////////////////////////////////////////////////////// |
seccastanova | 2:8b79efdd0127 | 554 | if( (tm2.wday==Alarm[IRDA].wday)&&((tm2.hour)==Alarm[IRDA].hour)&&(tm2.min==Alarm[IRDA].min)&&(tm2.sec==Alarm[IRDA].sec) ) |
Jepalacioh | 0:c2ed510ee88d | 555 | { |
Jepalacioh | 0:c2ed510ee88d | 556 | Lugar++; |
Jepalacioh | 0:c2ed510ee88d | 557 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 558 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 559 | lcd.printf("Active Alarm!!!"); |
Jepalacioh | 0:c2ed510ee88d | 560 | wait(1); |
Jepalacioh | 0:c2ed510ee88d | 561 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 562 | lcd.printf("->Turn off "); |
Jepalacioh | 0:c2ed510ee88d | 563 | lcd.locate(0,1); |
seccastanova | 2:8b79efdd0127 | 564 | lcd.printf("--Postpone "); |
Jepalacioh | 0:c2ed510ee88d | 565 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 566 | } |
seccastanova | 2:8b79efdd0127 | 567 | ////////////////// IRDA WAITING /////////////////////////////////////////////////////////////////////////////////////////////////// |
seccastanova | 2:8b79efdd0127 | 568 | if (button_enco.falling()) |
seccastanova | 2:8b79efdd0127 | 569 | { |
seccastanova | 2:8b79efdd0127 | 570 | irda_en=1; |
seccastanova | 2:8b79efdd0127 | 571 | lcd.cls(); |
seccastanova | 2:8b79efdd0127 | 572 | lcd.locate(0,0); |
seccastanova | 2:8b79efdd0127 | 573 | lcd.printf(" IRDA Waiting "); |
seccastanova | 2:8b79efdd0127 | 574 | |
seccastanova | 2:8b79efdd0127 | 575 | } |
Jepalacioh | 0:c2ed510ee88d | 576 | |
Jepalacioh | 0:c2ed510ee88d | 577 | break; |
Jepalacioh | 0:c2ed510ee88d | 578 | |
seccastanova | 2:8b79efdd0127 | 579 | case 3: //TURN OFF OR POSTPONE THE ALARM |
Jepalacioh | 0:c2ed510ee88d | 580 | |
seccastanova | 2:8b79efdd0127 | 581 | if(alarma==0) //CHOICE OF POSTPONE |
Jepalacioh | 0:c2ed510ee88d | 582 | { |
seccastanova | 2:8b79efdd0127 | 583 | myled=1; |
seccastanova | 2:8b79efdd0127 | 584 | wait(0.5); |
seccastanova | 2:8b79efdd0127 | 585 | myled=0; |
seccastanova | 2:8b79efdd0127 | 586 | wait(0.5); |
seccastanova | 2:8b79efdd0127 | 587 | |
Jepalacioh | 0:c2ed510ee88d | 588 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 589 | if(m!=0) |
Jepalacioh | 0:c2ed510ee88d | 590 | { |
Jepalacioh | 0:c2ed510ee88d | 591 | alarma=1; |
Jepalacioh | 0:c2ed510ee88d | 592 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 593 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 594 | |
Jepalacioh | 0:c2ed510ee88d | 595 | lcd.locate(1,0); |
Jepalacioh | 0:c2ed510ee88d | 596 | lcd.printf("-"); |
Jepalacioh | 0:c2ed510ee88d | 597 | lcd.locate(1,1); |
Jepalacioh | 0:c2ed510ee88d | 598 | lcd.printf(">"); |
Jepalacioh | 0:c2ed510ee88d | 599 | } |
Jepalacioh | 0:c2ed510ee88d | 600 | } |
Jepalacioh | 0:c2ed510ee88d | 601 | |
Jepalacioh | 0:c2ed510ee88d | 602 | /////////////////// |
Jepalacioh | 0:c2ed510ee88d | 603 | |
seccastanova | 2:8b79efdd0127 | 604 | if(alarma==1) //CHOICE OF TURN OFF |
Jepalacioh | 0:c2ed510ee88d | 605 | { |
seccastanova | 2:8b79efdd0127 | 606 | myled=1; |
seccastanova | 2:8b79efdd0127 | 607 | wait(0.5); |
seccastanova | 2:8b79efdd0127 | 608 | myled=0; |
seccastanova | 2:8b79efdd0127 | 609 | wait(0.5); |
seccastanova | 2:8b79efdd0127 | 610 | |
Jepalacioh | 0:c2ed510ee88d | 611 | m=wheel.getPulses(); |
Jepalacioh | 0:c2ed510ee88d | 612 | if(m!=0) |
Jepalacioh | 0:c2ed510ee88d | 613 | { |
Jepalacioh | 0:c2ed510ee88d | 614 | alarma=0; |
Jepalacioh | 0:c2ed510ee88d | 615 | m=0; |
Jepalacioh | 0:c2ed510ee88d | 616 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 617 | |
Jepalacioh | 0:c2ed510ee88d | 618 | lcd.locate(1,0); |
Jepalacioh | 0:c2ed510ee88d | 619 | lcd.printf(">"); |
Jepalacioh | 0:c2ed510ee88d | 620 | lcd.locate(1,1); |
Jepalacioh | 0:c2ed510ee88d | 621 | lcd.printf("-"); |
Jepalacioh | 0:c2ed510ee88d | 622 | } |
Jepalacioh | 0:c2ed510ee88d | 623 | } |
Jepalacioh | 0:c2ed510ee88d | 624 | |
Jepalacioh | 0:c2ed510ee88d | 625 | if (button_enco.falling()) |
Jepalacioh | 0:c2ed510ee88d | 626 | { |
Jepalacioh | 0:c2ed510ee88d | 627 | if(alarma==0) |
Jepalacioh | 0:c2ed510ee88d | 628 | { |
seccastanova | 2:8b79efdd0127 | 629 | Lugar=2; //RETURN TO SHOW THE TIME |
Jepalacioh | 0:c2ed510ee88d | 630 | wheel.reset(); |
Jepalacioh | 0:c2ed510ee88d | 631 | m=0; |
seccastanova | 2:8b79efdd0127 | 632 | myled=1; |
seccastanova | 2:8b79efdd0127 | 633 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 634 | } |
Jepalacioh | 0:c2ed510ee88d | 635 | if(alarma==1) |
Jepalacioh | 0:c2ed510ee88d | 636 | { |
seccastanova | 2:8b79efdd0127 | 637 | Lugar=2; //RETURN TO SHOW THE TIME WITH CURRENT ALARM UPDATED |
seccastanova | 2:8b79efdd0127 | 638 | rtc.getTime(tm2); |
Jepalacioh | 0:c2ed510ee88d | 639 | if(tm.min!=58) |
Jepalacioh | 0:c2ed510ee88d | 640 | { |
seccastanova | 2:8b79efdd0127 | 641 | Alarm[IRDA].min=tm2.min+1; |
Jepalacioh | 0:c2ed510ee88d | 642 | } |
Jepalacioh | 0:c2ed510ee88d | 643 | if(tm.min==59) |
Jepalacioh | 0:c2ed510ee88d | 644 | { |
seccastanova | 2:8b79efdd0127 | 645 | Alarm[IRDA].min=0; |
seccastanova | 2:8b79efdd0127 | 646 | Alarm[IRDA].hour=tm2.hour+1; |
Jepalacioh | 0:c2ed510ee88d | 647 | } |
seccastanova | 2:8b79efdd0127 | 648 | Alarm[IRDA].sec=tm2.sec; |
Jepalacioh | 0:c2ed510ee88d | 649 | lcd.cls(); |
Jepalacioh | 0:c2ed510ee88d | 650 | alarma=0; |
seccastanova | 2:8b79efdd0127 | 651 | myled=1; |
seccastanova | 2:8b79efdd0127 | 652 | } |
Jepalacioh | 0:c2ed510ee88d | 653 | } |
Jepalacioh | 0:c2ed510ee88d | 654 | break; |
seccastanova | 2:8b79efdd0127 | 655 | } |
seccastanova | 2:8b79efdd0127 | 656 | ///////////////////////////////// IRDA READING ////////////////////////////////////////////////////////////////////////////////// |
seccastanova | 2:8b79efdd0127 | 657 | while (irda_en) |
seccastanova | 2:8b79efdd0127 | 658 | { |
seccastanova | 2:8b79efdd0127 | 659 | fflush( stdin ); |
seccastanova | 2:8b79efdd0127 | 660 | lop2: if(!mode){ |
seccastanova | 2:8b79efdd0127 | 661 | header = irda.read_high_us(); |
seccastanova | 2:8b79efdd0127 | 662 | if(header>3500) goto seguir2; |
seccastanova | 2:8b79efdd0127 | 663 | goto lop2; |
seccastanova | 2:8b79efdd0127 | 664 | } |
seccastanova | 2:8b79efdd0127 | 665 | |
seccastanova | 2:8b79efdd0127 | 666 | seguir2: |
seccastanova | 2:8b79efdd0127 | 667 | for(i1=0;i1<numb;++i1){ |
seccastanova | 2:8b79efdd0127 | 668 | numP[i1] = irda.read_high_us(); //funcion para leer un pulso alto |
seccastanova | 2:8b79efdd0127 | 669 | if (numP[i1]<1000){ |
seccastanova | 2:8b79efdd0127 | 670 | s=0; |
seccastanova | 2:8b79efdd0127 | 671 | r='0'; |
seccastanova | 2:8b79efdd0127 | 672 | }else{ |
seccastanova | 2:8b79efdd0127 | 673 | s=1; |
seccastanova | 2:8b79efdd0127 | 674 | r='1'; |
seccastanova | 2:8b79efdd0127 | 675 | } |
seccastanova | 2:8b79efdd0127 | 676 | numbin[i1]=s; |
seccastanova | 2:8b79efdd0127 | 677 | cadena[i1]=r; |
seccastanova | 2:8b79efdd0127 | 678 | } |
seccastanova | 2:8b79efdd0127 | 679 | if (!strcmp(cadena,uno)){ |
seccastanova | 2:8b79efdd0127 | 680 | IRDA=1; |
seccastanova | 2:8b79efdd0127 | 681 | lcd.locate(8,1); |
seccastanova | 2:8b79efdd0127 | 682 | lcd.printf("%d",IRDA); |
seccastanova | 2:8b79efdd0127 | 683 | goto seguir2; |
seccastanova | 2:8b79efdd0127 | 684 | }else if (!strcmp(cadena,dos)){ |
seccastanova | 2:8b79efdd0127 | 685 | IRDA=2; |
seccastanova | 2:8b79efdd0127 | 686 | lcd.locate(8,1); |
seccastanova | 2:8b79efdd0127 | 687 | lcd.printf("%d",IRDA); |
seccastanova | 2:8b79efdd0127 | 688 | goto seguir2; |
seccastanova | 2:8b79efdd0127 | 689 | }else if (!strcmp(cadena,tres)){ |
seccastanova | 2:8b79efdd0127 | 690 | IRDA=3; |
seccastanova | 2:8b79efdd0127 | 691 | lcd.locate(8,1); |
seccastanova | 2:8b79efdd0127 | 692 | lcd.printf("%d",IRDA); |
seccastanova | 2:8b79efdd0127 | 693 | goto seguir2; |
seccastanova | 2:8b79efdd0127 | 694 | }else if (!strcmp(cadena,cuatro)){ |
seccastanova | 2:8b79efdd0127 | 695 | IRDA=4; |
seccastanova | 2:8b79efdd0127 | 696 | lcd.locate(8,1); |
seccastanova | 2:8b79efdd0127 | 697 | lcd.printf("%d",IRDA); |
seccastanova | 2:8b79efdd0127 | 698 | goto seguir2; |
seccastanova | 2:8b79efdd0127 | 699 | }else if (!strcmp(cadena,cinco)){ |
seccastanova | 2:8b79efdd0127 | 700 | IRDA=5; |
seccastanova | 2:8b79efdd0127 | 701 | lcd.locate(8,1); |
seccastanova | 2:8b79efdd0127 | 702 | lcd.printf("%d",IRDA); |
seccastanova | 2:8b79efdd0127 | 703 | goto seguir2; |
seccastanova | 2:8b79efdd0127 | 704 | }else if (!strcmp(cadena,seis)){ |
seccastanova | 2:8b79efdd0127 | 705 | IRDA=6; |
seccastanova | 2:8b79efdd0127 | 706 | lcd.locate(8,1); |
seccastanova | 2:8b79efdd0127 | 707 | lcd.printf("%d",IRDA); |
seccastanova | 2:8b79efdd0127 | 708 | goto seguir2; |
seccastanova | 2:8b79efdd0127 | 709 | }else if (!strcmp(cadena,siete)){ |
seccastanova | 2:8b79efdd0127 | 710 | IRDA=7; |
seccastanova | 2:8b79efdd0127 | 711 | lcd.locate(8,1); |
seccastanova | 2:8b79efdd0127 | 712 | lcd.printf("%d",IRDA); |
seccastanova | 2:8b79efdd0127 | 713 | goto seguir2; |
seccastanova | 2:8b79efdd0127 | 714 | }else if(!strcmp(cadena,set)){ |
seccastanova | 2:8b79efdd0127 | 715 | goto lop3; |
seccastanova | 2:8b79efdd0127 | 716 | } |
seccastanova | 2:8b79efdd0127 | 717 | lop3: Lugar=2; |
seccastanova | 2:8b79efdd0127 | 718 | irda_en=0; |
seccastanova | 2:8b79efdd0127 | 719 | lcd.cls(); |
seccastanova | 2:8b79efdd0127 | 720 | break; |
seccastanova | 2:8b79efdd0127 | 721 | } |
seccastanova | 2:8b79efdd0127 | 722 | } |
Jepalacioh | 0:c2ed510ee88d | 723 | } |