APS SO

Dependencies:   WebSocketClient mbed

Fork of APS_SO by Ian Bolfarini

Committer:
ianwillianb
Date:
Thu Oct 26 21:12:28 2017 +0000
Revision:
0:f603fa86c646
Child:
1:3da12598c635
0.1 - Implementando o RTC e fun??es suportes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ianwillianb 0:f603fa86c646 1 #include "mbed.h"
ianwillianb 0:f603fa86c646 2 #include "Rtc_Ds1307.h"
ianwillianb 0:f603fa86c646 3
ianwillianb 0:f603fa86c646 4
ianwillianb 0:f603fa86c646 5 //Inicialização do Led RGB
ianwillianb 0:f603fa86c646 6 DigitalOut led(LED_BLUE);
ianwillianb 0:f603fa86c646 7 //Inicialização do RTC
ianwillianb 0:f603fa86c646 8 Rtc_Ds1307 rtc(D14,D15);
ianwillianb 0:f603fa86c646 9 //Estrutura responsável por armazenar os dados do RTC
ianwillianb 0:f603fa86c646 10 Rtc_Ds1307::Time_rtc alarm_time ;
ianwillianb 0:f603fa86c646 11 //Estabelece comunicação serial para DEBUG
ianwillianb 0:f603fa86c646 12 Serial gSerial(USBTX, USBRX);
ianwillianb 0:f603fa86c646 13
ianwillianb 0:f603fa86c646 14 //Ajuste da hora atraves da interface serial
ianwillianb 0:f603fa86c646 15 void set_time_serial()
ianwillianb 0:f603fa86c646 16 {
ianwillianb 0:f603fa86c646 17 int hora, min, seg, dia, mes, ano, opt;
ianwillianb 0:f603fa86c646 18
ianwillianb 0:f603fa86c646 19 gSerial.printf("1-Ajuste de Hora, 2-Ajuste de Data, 3-Ajuste de Data/Hora);
ianwillianb 0:f603fa86c646 20 gSerial.scanf("%d",&opt);
ianwillianb 0:f603fa86c646 21
ianwillianb 0:f603fa86c646 22 if(opt == 1 || opt ==3 ) {
ianwillianb 0:f603fa86c646 23
ianwillianb 0:f603fa86c646 24 gSerial.printf("Insira a hora(HH MM SS): ");
ianwillianb 0:f603fa86c646 25 gSerial.scanf("%d %d %d", &hora, &min, &seg);
ianwillianb 0:f603fa86c646 26
ianwillianb 0:f603fa86c646 27 if( (hora < 24 && hora>=0) && (min>=0 && min <60) && (seg>=0 && seg <60))
ianwillianb 0:f603fa86c646 28 {
ianwillianb 0:f603fa86c646 29
ianwillianb 0:f603fa86c646 30 rtc.getTime(alarm_time);
ianwillianb 0:f603fa86c646 31 alarm_time.hour = hora;
ianwillianb 0:f603fa86c646 32 alarm_time.min = min;
ianwillianb 0:f603fa86c646 33 alarm_time.sec = seg;
ianwillianb 0:f603fa86c646 34 rtc.setTime(alarm_time, true, false);
ianwillianb 0:f603fa86c646 35 rtc.getTime(alarm_time);
ianwillianb 0:f603fa86c646 36 gSerial.printf("\nHora Ajustada: %2d:%02d:%02d \n",alarm_time.hour,alarm_time.min,alarm_time.sec);
ianwillianb 0:f603fa86c646 37
ianwillianb 0:f603fa86c646 38
ianwillianb 0:f603fa86c646 39 }
ianwillianb 0:f603fa86c646 40
ianwillianb 0:f603fa86c646 41 else gSerial.printf("Entrada Incorreta.\n");
ianwillianb 0:f603fa86c646 42
ianwillianb 0:f603fa86c646 43
ianwillianb 0:f603fa86c646 44 }
ianwillianb 0:f603fa86c646 45
ianwillianb 0:f603fa86c646 46
ianwillianb 0:f603fa86c646 47 if(opt==2 || opt ==3)
ianwillianb 0:f603fa86c646 48 {
ianwillianb 0:f603fa86c646 49
ianwillianb 0:f603fa86c646 50 gSerial.printf("Insira a data(DIA MES ANO): ");
ianwillianb 0:f603fa86c646 51 gSerial.scanf("%d %d %d", &dia, &mes, &ano);
ianwillianb 0:f603fa86c646 52
ianwillianb 0:f603fa86c646 53
ianwillianb 0:f603fa86c646 54
ianwillianb 0:f603fa86c646 55
ianwillianb 0:f603fa86c646 56 }
ianwillianb 0:f603fa86c646 57
ianwillianb 0:f603fa86c646 58
ianwillianb 0:f603fa86c646 59
ianwillianb 0:f603fa86c646 60
ianwillianb 0:f603fa86c646 61 }
ianwillianb 0:f603fa86c646 62
ianwillianb 0:f603fa86c646 63
ianwillianb 0:f603fa86c646 64
ianwillianb 0:f603fa86c646 65 int main()
ianwillianb 0:f603fa86c646 66 {
ianwillianb 0:f603fa86c646 67 //alarm_time.hour=16;
ianwillianb 0:f603fa86c646 68 //alarm_time.min=59;
ianwillianb 0:f603fa86c646 69 //alarm_time.sec=40;
ianwillianb 0:f603fa86c646 70 //rtc.setTime(alarm_time, true, false);
ianwillianb 0:f603fa86c646 71 // int hora=0;
ianwillianb 0:f603fa86c646 72 // gSerial.printf("Insira a hora:");
ianwillianb 0:f603fa86c646 73 //gSerial.scanf("%d",&hora);
ianwillianb 0:f603fa86c646 74 //gSerial.printf("Hora Inserida: %d" , hora);
ianwillianb 0:f603fa86c646 75 // rtc.getTime(alarm_time);
ianwillianb 0:f603fa86c646 76 //gSerial.printf("Data: %d/%d/%d\n\r",alarm_time.date,alarm_time.mon,alarm_time.year);
ianwillianb 0:f603fa86c646 77
ianwillianb 0:f603fa86c646 78 while (true) {
ianwillianb 0:f603fa86c646 79
ianwillianb 0:f603fa86c646 80 rtc.getTime(alarm_time);
ianwillianb 0:f603fa86c646 81 led = !led;
ianwillianb 0:f603fa86c646 82 gSerial.printf("\r");
ianwillianb 0:f603fa86c646 83 gSerial.printf("Hora: %2d:%02d:%02d \n",alarm_time.hour,alarm_time.min,alarm_time.sec);
ianwillianb 0:f603fa86c646 84 wait(1);
ianwillianb 0:f603fa86c646 85 }
ianwillianb 0:f603fa86c646 86
ianwillianb 0:f603fa86c646 87
ianwillianb 0:f603fa86c646 88 //set_time_serial();
ianwillianb 0:f603fa86c646 89
ianwillianb 0:f603fa86c646 90
ianwillianb 0:f603fa86c646 91
ianwillianb 0:f603fa86c646 92
ianwillianb 0:f603fa86c646 93 }