
.
Dependencies: Debounced QEI RTC-DS1307 TextLCD mbed
Fork of Reloj_alarma by
Revision 2:2f8b2690d757, committed 2017-11-30
- Comitter:
- alejom23
- Date:
- Thu Nov 30 19:41:20 2017 +0000
- Parent:
- 1:0639f31dd59f
- Commit message:
- Reloj de 7 Alarmas.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0639f31dd59f -r 2f8b2690d757 main.cpp --- a/main.cpp Wed Sep 28 06:48:39 2016 +0000 +++ b/main.cpp Thu Nov 30 19:41:20 2017 +0000 @@ -3,46 +3,96 @@ #include "TextLCD.h" #include "QEI.h" #include "Rtc_Ds1307.h" + +TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5);// rs, e, d4-d7 -TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 Rtc_Ds1307 rtc(PTE0, PTE1); QEI wheel (PTA16, PTA17, NC, 48); - + +DigitalOut led(PTE31); + DigitalOut led1(LED1); + DigitalOut led2(LED2); + DigitalOut led3(LED3); DebouncedIn button_enco(PTC5); - -PwmOut Sonido(PTA5); - -float periodo; -float Frecuencia=4000; int C1=0x0C; +int mes=0, dia=0, ano=0, hora=0,minuto=0,seg=0; int m; int Conf=0; // 0: Alarma y 1:Reloj int Lugar=0; // Definen el punto en el cual va el programa int i=0; int visual=0; int alarma=0; - +int j=0,k=0; +int x=1; +void pwr(); +bool alarma_existe=false; +bool control = false; +int configurada=0; +int d=0; +int cabeceraL=9000; +int cabeceraH=4555; +int Tdescanso=500; +int Tlow=630; +int Thigh=1750; +int duracion; //duracion de un pulso bajo +int numb = 33; +int code[65]; +const unsigned pwrHY[]={575,548,548,575,549,549,575,548,1686,1686,1686,1687,1685,1687,549,1686, + 1686,1686,576,548,549,576,549,549,576,549,1687,1687,1686,1686,1687,1686}; int main() { + led1=1;led2=1;led3=1; Rtc_Ds1307::Time_rtc tm = {}; - Rtc_Ds1307::Time_rtc Alarm = {}; + Rtc_Ds1307::Time_rtc Alarm[7] = {}; lcd.cls(); lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD lcd.locate(0,0); lcd.printf("--Alarma --Hora"); - - periodo=(1/Frecuencia); - Sonido.period(periodo); - - rtc.getTime(tm); //lee el tiempo del DS1307 + rtc.getTime(tm); + while(1) { + rtc.getTime(tm); + if(alarma_existe==true){ + while(x==1){ + if((Alarm[k].date==tm.date && Alarm[k].mon==tm.mon && Alarm[k].year==tm.year && Alarm[k].hour==tm.hour && Alarm[k].min==tm.min && Alarm[k].sec==tm.sec)){ + lcd.cls(); + lcd.locate(0,0); + led1=0;led2=0;led3=0; + lcd.printf("Alarma Activada!"); + lcd.locate(0,1); + lcd.printf("Prendido"); + control=true; + while(d==0){ + if(button_enco.falling()){ + pwr(); + x=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("--Alarma --Hora"); + Lugar=0; + i=0; + led1=1;led2=1;led3=1; + control = false; + d=1; + } + } + } + if(k==j){ + break; + } + k++; + } + k=0; + } + d=0; + x=1; switch (Lugar) { case 0: - m=wheel.getPulses(); // m son los datos del encoder + m = wheel.getPulses(); if(m!=0 && Conf==0){ Conf=1; wheel.reset(); @@ -76,7 +126,7 @@ wait(0.1); } - if (button_enco.falling()){ //si se pulsa boton encoder + if (button_enco.falling()){ Lugar++; m=0; } @@ -89,7 +139,7 @@ case 0: - if(Conf==0) + if(Conf==0 && j<6) { lcd.cls(); lcd.locate(0,0); @@ -100,10 +150,37 @@ lcd.cls(); lcd.locate(0,0); lcd.printf("Dia: "); - tm.date=1; + dia=1; + } + if(Conf==0 && j==6) + { + j=0; + while(j<7){ + lcd.cls(); + lcd.locate(0,0); + lcd.printf("H: "); + lcd.printf("%02d:",Alarm[j].hour); + lcd.printf("%02d:",Alarm[j].min); + lcd.printf("%02d",Alarm[j].sec); + lcd.locate(0,1); + lcd.printf("F: "); + lcd.printf("%02d:",Alarm[j].date); + lcd.printf("%02d:",Alarm[j].mon); + lcd.printf("%02d",Alarm[j].year); + wait(0.25); + if(button_enco.falling()){ + j++; + } + } + Lugar=0; + i=0; + j=0; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("--Alarma --Hora"); } - if(Conf==1) + if(Conf==1 && configurada==0) { lcd.cls(); lcd.locate(0,0); @@ -114,31 +191,77 @@ lcd.cls(); lcd.locate(0,0); lcd.printf("Dia: "); - - } - + //tm.date=1; + } + + if(Conf==1 && configurada==1) + { + rtc.getTime(tm); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("H: "); + lcd.printf("%02d:",tm.hour); + lcd.printf("%02d:",tm.min); + lcd.printf("%02d",tm.sec); + lcd.locate(0,1); + lcd.printf("F: "); + lcd.printf("%02d:",tm.date); + lcd.printf("%02d:",tm.mon); + lcd.printf("%02d",tm.year); + wait(0.25); + if(button_enco.falling()){ + Lugar=0; + i=0; + } + lcd.cls(); + lcd.locate(0,0); + lcd.printf("--Alarma --Hora"); + } break; case 1: + if(Conf==1){ m=wheel.getPulses(); if (m!=0) { - tm.date=tm.date+m; - if(tm.date>31) + dia=dia+m; + if(dia>31) { - tm.date=31; + dia=31; } - if(tm.date<1) + if(dia<1) { - tm.date=1; + dia=1; } wheel.reset(); m=0; } lcd.locate(5,0); - lcd.printf("%02d",tm.date); + lcd.printf("%02d",dia); + } + if(Conf==0){ + m=wheel.getPulses(); + if (m!=0) + { + dia = dia + m; + if(dia>31) + { + dia=31; + } + if(dia<1) + { + dia=1; + } + + wheel.reset(); + m=0; + } + lcd.locate(5,0); + lcd.printf("%02d",dia); + } + if (button_enco.falling()) { i++; @@ -152,25 +275,45 @@ break; case 2: - m=wheel.getPulses(); + m=wheel.getPulses(); + if(Conf==1){ if (m!=0) { - tm.mon=tm.mon+m; - if(tm.mon>12) + mes=mes+m; + if(mes>12) { - tm.mon=12; + mes=12; } - if(tm.mon<1) + if(mes<1) { - tm.mon=1; + mes=1; } wheel.reset(); m=0; } lcd.locate(5,0); - lcd.printf("%02d",tm.mon); - + lcd.printf("%02d",mes); + } + if(Conf==0){ + if (m!=0) + { + mes=mes+m; + if(mes>12) + { + mes=12; + } + if(mes<1) + { + mes=1; + } + + wheel.reset(); + m=0; + } + lcd.locate(5,0); + lcd.printf("%02d",mes); + } if (button_enco.falling()) { i++; @@ -178,28 +321,45 @@ lcd.cls(); lcd.locate(0,0); lcd.printf("Year: "); - + //tm.year=2000; } break; case 3: - m=wheel.getPulses(); + m=wheel.getPulses(); + if(Conf==1){ if (m!=0) { - tm.year=tm.year+m; + ano=ano+m; - if(tm.year<2000) + if(ano<2000) { - tm.year=2000; + ano=2000; } wheel.reset(); m=0; } lcd.locate(6,0); - lcd.printf("%02d",tm.year); - + lcd.printf("%02d",ano); + } + if(Conf==0){ + if (m!=0) + { + ano=ano + m; + + if(ano<2000) + { + ano=2000; + } + + wheel.reset(); + m=0; + } + lcd.locate(6,0); + lcd.printf("%02d",ano); + } if (button_enco.falling()) { i++; @@ -207,32 +367,51 @@ lcd.cls(); lcd.locate(0,0); lcd.printf("Hora: "); - + //tm.hour=5; } break; case 4: m=wheel.getPulses(); - + if(Conf==1){ if (m!=0) { - tm.hour=tm.hour + m; - if(tm.hour>23) + hora=hora+ m; + if(hora>23) { - tm.hour=23; + hora=23; } - if(tm.hour<0) + if(hora<0) { - tm.hour=0; + hora=0; } wheel.reset(); m=0; } lcd.locate(6,0); - lcd.printf("%02d",tm.hour); - + lcd.printf("%02d",hora); + } + if(Conf==0){ + if (m!=0) + { + hora=hora + m; + if(hora>23) + { + hora=23; + } + if(hora<0) + { + hora=0; + } + + wheel.reset(); + m=0; + } + lcd.locate(6,0); + lcd.printf("%02d",hora); + } if (button_enco.falling()) { i++; @@ -246,25 +425,45 @@ break; case 5: - m=wheel.getPulses(); + m=wheel.getPulses(); + if(Conf==1){ if (m!=0) { - tm.min=tm.min+m; - if(tm.min>59) + minuto=minuto+m; + if(minuto>59) { - tm.min=59; + minuto=59; } - if(tm.min<0) + if(minuto<0) { - tm.min=0; + minuto=0; } wheel.reset(); m=0; } lcd.locate(8,0); - lcd.printf("%02d",tm.min); - + lcd.printf("%02d",minuto); + } + if(Conf==0){ + if (m!=0) + { + minuto=minuto+m; + if(minuto>59) + { + minuto=59; + } + if(minuto<0) + { + minuto=0; + } + + wheel.reset(); + m=0; + } + lcd.locate(8,0); + lcd.printf("%02d",minuto); + } if (button_enco.falling()) { i++; @@ -279,44 +478,79 @@ case 6: - m=wheel.getPulses(); + m=wheel.getPulses(); + if(Conf==1){ if (m!=0) { - tm.sec=tm.sec+m; - if(tm.sec>59) + seg=seg+m; + if(seg>59) + { + seg=59; + } + if(seg<0) { - tm.sec=59; + seg=0; } - if(tm.sec<0) + + wheel.reset(); + m=0; + } + lcd.locate(9,0); + lcd.printf("%02d",seg); + } + if(Conf==0){ + if (m!=0) + { + seg=seg+m; + if(seg>59) { - tm.sec=0; + seg=59; + } + if(seg<0) + { + seg=0; } wheel.reset(); m=0; } lcd.locate(9,0); - lcd.printf("%02d",tm.sec); - + lcd.printf("%02d",seg); + } if (button_enco.falling()) { /////////////////// if(Conf==0) { - Alarm=tm; lcd.cls(); lcd.locate(0,0); lcd.printf("Alarma config. "); wait(1); i=0; m=0; - Lugar++; + Lugar=0; lcd.cls(); - + alarma_existe=true; + Alarm[j].year=ano; + Alarm[j].mon=mes; + Alarm[j].date=dia; + Alarm[j].min=minuto; + Alarm[j].sec=seg; + Alarm[j].hour=hora; + j++; + lcd.cls(); + lcd.locate(0,0); + lcd.printf("--Alarma --Hora"); } if(Conf==1) { + tm.year=ano; + tm.mon=mes; + tm.date=dia; + tm.min=minuto; + tm.sec=seg; + tm.hour=hora; rtc.setTime(tm, false, false); rtc.startClock(); lcd.cls(); @@ -325,6 +559,7 @@ wait(1); i=0; m=0; + configurada=1; Lugar=0; lcd.locate(0,0); lcd.printf("--Alarma --Hora"); @@ -336,173 +571,63 @@ break; } - break; - - case 2: - - rtc.getTime(tm); - - if(visual==0) - { - - lcd.locate(0,0); - lcd.printf("Hora: "); - lcd.locate(8,0); - lcd.printf("%02d:",tm.hour); - lcd.printf("%02d:",tm.min); - lcd.printf("%02d",tm.sec); - - lcd.locate(0,1); - lcd.printf("%02d/",tm.mon); - lcd.printf("%02d/",tm.date); - lcd.printf("%02d",tm.year); - wait(0.1); - ////////// - m=wheel.getPulses(); - if(m!=0) - { - visual=1; - wheel.reset(); - m=0; - } - - ////// - - } - - if(visual==1) - { - lcd.locate(0,0); - lcd.printf("Alarma: "); - lcd.locate(8,0); - lcd.printf("%02d:",Alarm.hour); - lcd.printf("%02d:",Alarm.min); - lcd.printf("%02d",Alarm.sec); - - - lcd.locate(0,1); - lcd.printf("%02d/",Alarm.mon); - lcd.printf("%02d/",Alarm.date); - lcd.printf("%02d",Alarm.year); - wait(0.1); - //// - m=wheel.getPulses(); - if(m!=0) - { - visual=0; - wheel.reset(); - m=0; - } - - //// - } - - 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) ) - { - Lugar++; - lcd.cls(); - lcd.locate(0,0); - lcd.printf("Alarma Activa!!!"); - wait(1); - lcd.locate(0,0); - lcd.printf("->Desactivar "); - lcd.locate(0,1); - lcd.printf("--Aplazar "); - m=0; - } - - break; + - case 3: - - if(alarma==0) - { - Sonido.write(0.5); - wait(0.2); - Sonido.write(0); - wait(0.2); - Sonido.write(0.5); - wait(0.2); - Sonido.write(0); - wait(0.2); - - m=wheel.getPulses(); - if(m!=0) - { - alarma=1; - m=0; - wheel.reset(); - - lcd.locate(1,0); - lcd.printf("-"); - lcd.locate(1,1); - lcd.printf(">"); - } - } - - /////////////////// - - if(alarma==1) - { - Sonido.write(0.5); - wait(0.2); - Sonido.write(0); - wait(0.2); - Sonido.write(0.5); - wait(0.2); - Sonido.write(0); - wait(0.2); - - m=wheel.getPulses(); - if(m!=0) - { - alarma=0; - m=0; - wheel.reset(); - - lcd.locate(1,0); - lcd.printf(">"); - lcd.locate(1,1); - lcd.printf("-"); - } - } - - if (button_enco.falling()) - { - if(alarma==0) - { - Lugar=0; - wheel.reset(); - m=0; - Sonido.write(0); - lcd.cls(); - lcd.locate(0,0); - lcd.printf("--Alarma --Hora"); - - } - if(alarma==1) - { - Lugar=2; - rtc.getTime(tm); - if(tm.min!=58) - { - Alarm.min=tm.min+1; - } - if(tm.min==59) - { - Alarm.min=0; - Alarm.hour=tm.hour+1; - } - Alarm.sec=tm.sec; - lcd.cls(); - alarma=0; - - } - - } - - - break; - } } -} \ No newline at end of file +} +} + +int descanso(int duracion){ + Timer t; + t.reset(); + t.start(); + while(1) + { + led=1; + wait_us(8); + led=0; + led=0; + wait_us(9); + if(t.read_us() > duracion) return 0; + + } + } + +int sendcode(int numb, int *code, int cabeceraL, int cabeceraH, int Tdescanso, int Tlow, int Thigh) +{ + led=0; + wait_ms(100); + descanso(cabeceraL); + wait_us(cabeceraH); + + for(i=0;i<numb;i++){ + if (code[i]>1000){ + led=1; + descanso(Tdescanso); + wait_us(Thigh); + } + if (code[i]<1000){ + led=0; + descanso(Tdescanso); + wait_us(Tlow); + } + } + descanso(Tdescanso); + return 0; +} + +void pwr(){ + for(i=0;i<numb;i++){ + code[i]=pwrHY[i]; + } +sendcode(numb,code,cabeceraL, cabeceraH, Tdescanso, Tlow, Thigh); +} +//**************************** + +void repeat(){ + wait_ms(42); + descanso(8800); + wait_us(2240); + descanso(560); + } +