.
Dependencies: RTC-DS1307 Servo mbed
Fork of Progetto_Tandem_Finale by
Diff: main.cpp
- Revision:
- 2:e67f3b884a1c
- Parent:
- 1:0e967fe8862e
- Child:
- 3:7634bf23197f
diff -r 0e967fe8862e -r e67f3b884a1c main.cpp --- a/main.cpp Mon Apr 18 21:04:36 2016 +0000 +++ b/main.cpp Mon Apr 18 21:52:45 2016 +0000 @@ -1,6 +1,7 @@ #include "mbed.h" #include "note.h" #include "Servo.h" +#include "Rtc_Ds1307.h" DigitalIn bottone(p14); DigitalOut ledR(p25); @@ -9,79 +10,106 @@ PwmOut piezo(p22); Servo myservo1(p23); Servo myservo2(p21); +Rtc_Ds1307 rtc( p9,p10 ); +Serial pc(USBTX, USBRX, "pc"); + int c=0; +int a=0; +int b=0; +int f=0; +int orario_pastiglia=0, ultimo_giorno=0; +int flag=0; void suono(int frequenza, int beat); +void movimento_servi(); +void seriale(Rtc_Ds1307::Time_rtc time); int main() { + Rtc_Ds1307::Time_rtc time= {}; + ledB=1; + suono(NOTE_B4,1); + wait(0.5); + seriale(time); while(1) { - c=0; - if(bottone==1) { + if(bottone) { + flag=0; ledG=1; - ledR=0; - suono(NOTE_B4,1); - wait(1); - + suono(NOTE_B4,8); + wait_ms(1); do { - wait(0.001); + flag=0; + wait_ms(1); c++; if(c++>=10000) { ledG=0; ledR=1; suono(NOTE_C5,1); - } - } while(!bottone); - //*************************MOVIMENTO SERVI************************ - int a=0; - int b=0; - if(a<2) a++; - else if(a>=2) { - for(float i=0; i<30; i++) { - myservo1=i; - wait(0.1); - a=0; - b++; - } + flag=1; + } else if(bottone) flag=2; + } while(flag==0); + ledR=0; + if(flag==3) { + movimento_servi(); } - if(b==5){ - for(float i=180; i<0; i++) - myservo1=i; - wait(0.1); - b=0; - } - int f=0; - - if(f==0){ - for(float i=0; i<30; i++) - myservo2=i; - wait(0.1); - f++; - } - else if(f==1) - for(float i=0; i<60; i++) - myservo2=i; - wait(0.1); - f++; - if(f==3){ - for(float i=60; i<0; i--) - myservo2=i; - wait(0.1); - f=0; - } - - //**************************************************************** - - ledR=0; - ledB=1; - wait(1); - ledB=0; - suono(NOTE_F1,1); } + + if(ultimo_giorno!=time.date) { + if(orario_pastiglia==time.hour) { + movimento_servi(); + ultimo_giorno=time.date; + } else if(time.hour==orario_pastiglia-1 || time.hour>orario_pastiglia) { + movimento_servi(); + ultimo_giorno=time.date; + } + }//gia fatto oggi? + wait_ms(1); + } +} +/* +pc.printf("a=%d03", a); +pc.printf("b=%d03", b); +*/ +void movimento_servi() +{ + if(a<2) { + a++; + pc.printf("a=%d03", a); + } else if(a>=2) { + for(float i=0; i<30; i++) { + myservo1=i; + wait(0.1); + a=0; + b++; + pc.printf("b=%d03", b); + } + } + if(b==5) { + for(float i=180; i<0; i++) + myservo1=i; + wait(0.1); + b=0; + } + + if(f==0) { + for(float i=0; i<30; i++) + myservo2=i; + wait(0.1); + f++; + } else if(f==1) + for(float i=0; i<60; i++) + myservo2=i; + wait(0.1); + f++; + if(f==3) { + for(float i=60; i<0; i--) + myservo2=i; + wait(0.1); + f=0; } } @@ -92,4 +120,38 @@ wait(1.0 / beat); piezo.write(0); wait(0.05); -} \ No newline at end of file +} + +void seriale(Rtc_Ds1307::Time_rtc time) +{ + int s; + pc.printf("**********************************\n"); + pc.printf("* Menu : *\n"); + pc.printf("* 1 - imposta ora orologio *\n"); + pc.printf("* 2 - imposta ora pastiglia *\n"); + pc.printf("* 3 - mostra settaggi *\n"); + pc.scanf("%d", &s); + switch(s) { + case 1: + pc.printf("Giorno (0..31)"); + pc.scanf("%d", &time.date); + pc.printf("Mese (1..12)"); + pc.scanf("%d", &time.mon); + pc.printf("Anno "); + pc.scanf("%d", &time.year); + pc.printf("Ore (0..23)"); + pc.scanf("%d", &time.hour); + pc.printf("Minuti (0..59)"); + pc.scanf("%d", &time.min); + pc.printf("Secondi (0..59)"); + pc.scanf("%d", &time.sec); + break; + case 2: + pc.printf("Orario pastiglia"); + pc.scanf("%d", &orario_pastiglia); + break; + case 3: + 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); + break; + } +}