.

Dependencies:   RTC-DS1307 mbed

Committer:
Karrots3
Date:
Mon Apr 18 19:20:22 2016 +0000
Revision:
3:0fa42a66a4a6
Parent:
2:d3b43d747191
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Karrots3 0:3fa629914ea5 1 #include "mbed.h"
Karrots3 0:3fa629914ea5 2 #include "Rtc_Ds1307.h"
Karrots3 0:3fa629914ea5 3 #include "note.h"
Karrots3 0:3fa629914ea5 4
Karrots3 0:3fa629914ea5 5 DigitalIn bottone1(p23);
Karrots3 2:d3b43d747191 6 DigitalOut ledR(p25);
Karrots3 2:d3b43d747191 7 DigitalOut ledG(p24);
Karrots3 2:d3b43d747191 8 DigitalOut ledB(p26);
Karrots3 2:d3b43d747191 9 Rtc_Ds1307 rtc( p9,p10 );
Karrots3 2:d3b43d747191 10 PwmOut piezo(p22);
Karrots3 0:3fa629914ea5 11
Karrots3 0:3fa629914ea5 12 Serial pc(USBTX, USBRX, "pc");
Karrots3 0:3fa629914ea5 13
Karrots3 3:0fa42a66a4a6 14 bool flag1=0;
Karrots3 0:3fa629914ea5 15 int ultimo_giorno=0;
Karrots3 0:3fa629914ea5 16 int orario;
Karrots3 0:3fa629914ea5 17 long long int c;
Karrots3 3:0fa42a66a4a6 18
Karrots3 0:3fa629914ea5 19
Karrots3 0:3fa629914ea5 20 void suono(int frequenza, int beat);
Karrots3 0:3fa629914ea5 21 void seriale(Rtc_Ds1307::Time_rtc time);
Karrots3 0:3fa629914ea5 22
Karrots3 0:3fa629914ea5 23 int main()
Karrots3 0:3fa629914ea5 24 {
Karrots3 0:3fa629914ea5 25 Rtc_Ds1307::Time_rtc time= {};
Karrots3 3:0fa42a66a4a6 26 seriale(time);
Karrots3 0:3fa629914ea5 27 while(1) {
Karrots3 0:3fa629914ea5 28 if(ultimo_giorno!=time.date) { //if ultimo giorno è oggi
Karrots3 0:3fa629914ea5 29 if(orario == time.hour) { //if è l'ora della pappa
Karrots3 3:0fa42a66a4a6 30 ledB=1;
Karrots3 3:0fa42a66a4a6 31 suono(NOTE_B4,1);
Karrots3 0:3fa629914ea5 32 ultimo_giorno=time.date;
Karrots3 0:3fa629914ea5 33 } else if(bottone1 && time.hour==(orario-1) && time.min>=30) { //30 min prima
Karrots3 3:0fa42a66a4a6 34 ledR=1;
Karrots3 3:0fa42a66a4a6 35 suono(NOTE_B4,1);
Karrots3 0:3fa629914ea5 36 ultimo_giorno=time.date;
Karrots3 0:3fa629914ea5 37 } else if(bottone1 && time.hour>orario) { //l'ora è gia passata ma devo ancora prenderlo
Karrots3 3:0fa42a66a4a6 38 ledG=1;
Karrots3 3:0fa42a66a4a6 39 suono(NOTE_B4,1);
Karrots3 0:3fa629914ea5 40 ultimo_giorno=time.date;
Karrots3 0:3fa629914ea5 41 } else {
Karrots3 0:3fa629914ea5 42 if(bottone1) { //l'ora deve ancora venire e premo bottone
Karrots3 0:3fa629914ea5 43 ledR=1;
Karrots3 0:3fa629914ea5 44 suono(NOTE_B4,1);
Karrots3 0:3fa629914ea5 45 wait(1);
Karrots3 0:3fa629914ea5 46 ledR=0;
Karrots3 0:3fa629914ea5 47 }
Karrots3 0:3fa629914ea5 48 }
Karrots3 0:3fa629914ea5 49 } else { //gia fatto oggi e premo bottone
Karrots3 0:3fa629914ea5 50 if(bottone1) {
Karrots3 0:3fa629914ea5 51 ledR=1;
Karrots3 0:3fa629914ea5 52 suono(NOTE_B4,1);
Karrots3 0:3fa629914ea5 53 }
Karrots3 0:3fa629914ea5 54 }
Karrots3 0:3fa629914ea5 55 }//while(1)
Karrots3 0:3fa629914ea5 56 }//main
Karrots3 0:3fa629914ea5 57
Karrots3 0:3fa629914ea5 58 void suono(int frequenza, int beat)
Karrots3 0:3fa629914ea5 59 {
Karrots3 0:3fa629914ea5 60 piezo.period(1.0 / frequenza);
Karrots3 0:3fa629914ea5 61 piezo.write(0.5);
Karrots3 0:3fa629914ea5 62 wait(1.0 / beat);
Karrots3 0:3fa629914ea5 63 piezo.write(0);
Karrots3 0:3fa629914ea5 64 wait(0.05);
Karrots3 0:3fa629914ea5 65 }
Karrots3 0:3fa629914ea5 66
Karrots3 0:3fa629914ea5 67
Karrots3 0:3fa629914ea5 68
Karrots3 3:0fa42a66a4a6 69 void seriale(Rtc_Ds1307::Time_rtc time)
Karrots3 3:0fa42a66a4a6 70 {
Karrots3 0:3fa629914ea5 71 int c;
Karrots3 0:3fa629914ea5 72
Karrots3 0:3fa629914ea5 73
Karrots3 0:3fa629914ea5 74 pc.printf("**********************************\n");
Karrots3 0:3fa629914ea5 75 pc.printf("* Menu : *\n");
Karrots3 0:3fa629914ea5 76 pc.printf("* 1 - imposta ora orologio *\n");
Karrots3 0:3fa629914ea5 77 pc.printf("* 2 - imposta ora pastiglia *\n");
Karrots3 0:3fa629914ea5 78 pc.printf("* 3 - mostra settaggi *\n");
Karrots3 0:3fa629914ea5 79 pc.scanf("%d", &c);
Karrots3 0:3fa629914ea5 80
Karrots3 0:3fa629914ea5 81 switch(c) {
Karrots3 0:3fa629914ea5 82 case 1:
Karrots3 0:3fa629914ea5 83 pc.printf("Giorno (0..31)");
Karrots3 0:3fa629914ea5 84 pc.scanf("%d", &time.date);
Karrots3 0:3fa629914ea5 85 pc.printf("Mese (1..12)");
Karrots3 0:3fa629914ea5 86 pc.scanf("%d", &time.mon);
Karrots3 0:3fa629914ea5 87 pc.printf("Anno ");
Karrots3 0:3fa629914ea5 88 pc.scanf("%d", &time.year);
Karrots3 0:3fa629914ea5 89 pc.printf("Ore (0..23)");
Karrots3 0:3fa629914ea5 90 pc.scanf("%d", &time.hour);
Karrots3 0:3fa629914ea5 91 pc.printf("Minuti (0..59)");
Karrots3 0:3fa629914ea5 92 pc.scanf("%d", &time.min);
Karrots3 0:3fa629914ea5 93 pc.printf("Secondi (0..59)");
Karrots3 0:3fa629914ea5 94 pc.scanf("%d", &time.sec);
Karrots3 0:3fa629914ea5 95 break;
Karrots3 0:3fa629914ea5 96 case 2:
Karrots3 0:3fa629914ea5 97 pc.printf("Orario pastiglia");
Karrots3 0:3fa629914ea5 98 pc.scanf("%d", &orario);
Karrots3 0:3fa629914ea5 99 break;
Karrots3 0:3fa629914ea5 100 case 3:
Karrots3 0:3fa629914ea5 101 pc.printf("Ora sono le : %02d:%02d:%02d del %02d/%02d/%04d \n", time.hour, time.min, time.sec, time.mon, time.date, time.year);
Karrots3 0:3fa629914ea5 102 break;
Karrots3 0:3fa629914ea5 103 }
Karrots3 0:3fa629914ea5 104 }