![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
.
Dependencies: RTC-DS1307 Servo mbed
Fork of Progetto_Tandem_Finale by
main.cpp@2:e67f3b884a1c, 2016-04-18 (annotated)
- Committer:
- Karrots3
- Date:
- Mon Apr 18 21:52:45 2016 +0000
- Revision:
- 2:e67f3b884a1c
- Parent:
- 1:0e967fe8862e
- Child:
- 3:7634bf23197f
.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Karrots3 | 0:5daff114eb4a | 1 | #include "mbed.h" |
EzDzO | 1:0e967fe8862e | 2 | #include "note.h" |
EzDzO | 1:0e967fe8862e | 3 | #include "Servo.h" |
Karrots3 | 2:e67f3b884a1c | 4 | #include "Rtc_Ds1307.h" |
EzDzO | 1:0e967fe8862e | 5 | |
EzDzO | 1:0e967fe8862e | 6 | DigitalIn bottone(p14); |
Karrots3 | 0:5daff114eb4a | 7 | DigitalOut ledR(p25); |
Karrots3 | 0:5daff114eb4a | 8 | DigitalOut ledG(p24); |
Karrots3 | 0:5daff114eb4a | 9 | DigitalOut ledB(p26); |
Karrots3 | 0:5daff114eb4a | 10 | PwmOut piezo(p22); |
EzDzO | 1:0e967fe8862e | 11 | Servo myservo1(p23); |
EzDzO | 1:0e967fe8862e | 12 | Servo myservo2(p21); |
Karrots3 | 2:e67f3b884a1c | 13 | Rtc_Ds1307 rtc( p9,p10 ); |
Karrots3 | 2:e67f3b884a1c | 14 | Serial pc(USBTX, USBRX, "pc"); |
Karrots3 | 2:e67f3b884a1c | 15 | |
Karrots3 | 0:5daff114eb4a | 16 | int c=0; |
Karrots3 | 2:e67f3b884a1c | 17 | int a=0; |
Karrots3 | 2:e67f3b884a1c | 18 | int b=0; |
Karrots3 | 2:e67f3b884a1c | 19 | int f=0; |
Karrots3 | 2:e67f3b884a1c | 20 | int orario_pastiglia=0, ultimo_giorno=0; |
Karrots3 | 2:e67f3b884a1c | 21 | int flag=0; |
EzDzO | 1:0e967fe8862e | 22 | |
EzDzO | 1:0e967fe8862e | 23 | void suono(int frequenza, int beat); |
Karrots3 | 2:e67f3b884a1c | 24 | void movimento_servi(); |
Karrots3 | 2:e67f3b884a1c | 25 | void seriale(Rtc_Ds1307::Time_rtc time); |
EzDzO | 1:0e967fe8862e | 26 | |
Karrots3 | 0:5daff114eb4a | 27 | int main() |
Karrots3 | 0:5daff114eb4a | 28 | { |
Karrots3 | 2:e67f3b884a1c | 29 | Rtc_Ds1307::Time_rtc time= {}; |
Karrots3 | 2:e67f3b884a1c | 30 | ledB=1; |
Karrots3 | 2:e67f3b884a1c | 31 | suono(NOTE_B4,1); |
Karrots3 | 2:e67f3b884a1c | 32 | wait(0.5); |
Karrots3 | 2:e67f3b884a1c | 33 | seriale(time); |
Karrots3 | 0:5daff114eb4a | 34 | while(1) { |
Karrots3 | 0:5daff114eb4a | 35 | |
Karrots3 | 2:e67f3b884a1c | 36 | if(bottone) { |
Karrots3 | 2:e67f3b884a1c | 37 | flag=0; |
EzDzO | 1:0e967fe8862e | 38 | ledG=1; |
Karrots3 | 2:e67f3b884a1c | 39 | suono(NOTE_B4,8); |
Karrots3 | 2:e67f3b884a1c | 40 | wait_ms(1); |
EzDzO | 1:0e967fe8862e | 41 | do { |
Karrots3 | 2:e67f3b884a1c | 42 | flag=0; |
Karrots3 | 2:e67f3b884a1c | 43 | wait_ms(1); |
EzDzO | 1:0e967fe8862e | 44 | c++; |
EzDzO | 1:0e967fe8862e | 45 | if(c++>=10000) { |
EzDzO | 1:0e967fe8862e | 46 | ledG=0; |
EzDzO | 1:0e967fe8862e | 47 | ledR=1; |
EzDzO | 1:0e967fe8862e | 48 | suono(NOTE_C5,1); |
Karrots3 | 2:e67f3b884a1c | 49 | flag=1; |
Karrots3 | 2:e67f3b884a1c | 50 | } else if(bottone) flag=2; |
Karrots3 | 2:e67f3b884a1c | 51 | } while(flag==0); |
Karrots3 | 2:e67f3b884a1c | 52 | ledR=0; |
Karrots3 | 2:e67f3b884a1c | 53 | if(flag==3) { |
Karrots3 | 2:e67f3b884a1c | 54 | movimento_servi(); |
EzDzO | 1:0e967fe8862e | 55 | } |
Karrots3 | 0:5daff114eb4a | 56 | } |
Karrots3 | 0:5daff114eb4a | 57 | |
Karrots3 | 2:e67f3b884a1c | 58 | |
Karrots3 | 2:e67f3b884a1c | 59 | if(ultimo_giorno!=time.date) { |
Karrots3 | 2:e67f3b884a1c | 60 | if(orario_pastiglia==time.hour) { |
Karrots3 | 2:e67f3b884a1c | 61 | movimento_servi(); |
Karrots3 | 2:e67f3b884a1c | 62 | ultimo_giorno=time.date; |
Karrots3 | 2:e67f3b884a1c | 63 | } else if(time.hour==orario_pastiglia-1 || time.hour>orario_pastiglia) { |
Karrots3 | 2:e67f3b884a1c | 64 | movimento_servi(); |
Karrots3 | 2:e67f3b884a1c | 65 | ultimo_giorno=time.date; |
Karrots3 | 2:e67f3b884a1c | 66 | } |
Karrots3 | 2:e67f3b884a1c | 67 | }//gia fatto oggi? |
Karrots3 | 2:e67f3b884a1c | 68 | |
Karrots3 | 0:5daff114eb4a | 69 | wait_ms(1); |
Karrots3 | 2:e67f3b884a1c | 70 | } |
Karrots3 | 2:e67f3b884a1c | 71 | } |
Karrots3 | 2:e67f3b884a1c | 72 | /* |
Karrots3 | 2:e67f3b884a1c | 73 | pc.printf("a=%d03", a); |
Karrots3 | 2:e67f3b884a1c | 74 | pc.printf("b=%d03", b); |
Karrots3 | 2:e67f3b884a1c | 75 | */ |
Karrots3 | 2:e67f3b884a1c | 76 | void movimento_servi() |
Karrots3 | 2:e67f3b884a1c | 77 | { |
Karrots3 | 2:e67f3b884a1c | 78 | if(a<2) { |
Karrots3 | 2:e67f3b884a1c | 79 | a++; |
Karrots3 | 2:e67f3b884a1c | 80 | pc.printf("a=%d03", a); |
Karrots3 | 2:e67f3b884a1c | 81 | } else if(a>=2) { |
Karrots3 | 2:e67f3b884a1c | 82 | for(float i=0; i<30; i++) { |
Karrots3 | 2:e67f3b884a1c | 83 | myservo1=i; |
Karrots3 | 2:e67f3b884a1c | 84 | wait(0.1); |
Karrots3 | 2:e67f3b884a1c | 85 | a=0; |
Karrots3 | 2:e67f3b884a1c | 86 | b++; |
Karrots3 | 2:e67f3b884a1c | 87 | pc.printf("b=%d03", b); |
Karrots3 | 2:e67f3b884a1c | 88 | } |
Karrots3 | 2:e67f3b884a1c | 89 | } |
Karrots3 | 2:e67f3b884a1c | 90 | if(b==5) { |
Karrots3 | 2:e67f3b884a1c | 91 | for(float i=180; i<0; i++) |
Karrots3 | 2:e67f3b884a1c | 92 | myservo1=i; |
Karrots3 | 2:e67f3b884a1c | 93 | wait(0.1); |
Karrots3 | 2:e67f3b884a1c | 94 | b=0; |
Karrots3 | 2:e67f3b884a1c | 95 | } |
Karrots3 | 0:5daff114eb4a | 96 | |
Karrots3 | 2:e67f3b884a1c | 97 | |
Karrots3 | 2:e67f3b884a1c | 98 | if(f==0) { |
Karrots3 | 2:e67f3b884a1c | 99 | for(float i=0; i<30; i++) |
Karrots3 | 2:e67f3b884a1c | 100 | myservo2=i; |
Karrots3 | 2:e67f3b884a1c | 101 | wait(0.1); |
Karrots3 | 2:e67f3b884a1c | 102 | f++; |
Karrots3 | 2:e67f3b884a1c | 103 | } else if(f==1) |
Karrots3 | 2:e67f3b884a1c | 104 | for(float i=0; i<60; i++) |
Karrots3 | 2:e67f3b884a1c | 105 | myservo2=i; |
Karrots3 | 2:e67f3b884a1c | 106 | wait(0.1); |
Karrots3 | 2:e67f3b884a1c | 107 | f++; |
Karrots3 | 2:e67f3b884a1c | 108 | if(f==3) { |
Karrots3 | 2:e67f3b884a1c | 109 | for(float i=60; i<0; i--) |
Karrots3 | 2:e67f3b884a1c | 110 | myservo2=i; |
Karrots3 | 2:e67f3b884a1c | 111 | wait(0.1); |
Karrots3 | 2:e67f3b884a1c | 112 | f=0; |
Karrots3 | 0:5daff114eb4a | 113 | } |
Karrots3 | 0:5daff114eb4a | 114 | } |
EzDzO | 1:0e967fe8862e | 115 | |
EzDzO | 1:0e967fe8862e | 116 | void suono(int frequenza, int beat) |
EzDzO | 1:0e967fe8862e | 117 | { |
EzDzO | 1:0e967fe8862e | 118 | piezo.period(1.0 / frequenza); |
EzDzO | 1:0e967fe8862e | 119 | piezo.write(0.5); |
EzDzO | 1:0e967fe8862e | 120 | wait(1.0 / beat); |
EzDzO | 1:0e967fe8862e | 121 | piezo.write(0); |
EzDzO | 1:0e967fe8862e | 122 | wait(0.05); |
Karrots3 | 2:e67f3b884a1c | 123 | } |
Karrots3 | 2:e67f3b884a1c | 124 | |
Karrots3 | 2:e67f3b884a1c | 125 | void seriale(Rtc_Ds1307::Time_rtc time) |
Karrots3 | 2:e67f3b884a1c | 126 | { |
Karrots3 | 2:e67f3b884a1c | 127 | int s; |
Karrots3 | 2:e67f3b884a1c | 128 | pc.printf("**********************************\n"); |
Karrots3 | 2:e67f3b884a1c | 129 | pc.printf("* Menu : *\n"); |
Karrots3 | 2:e67f3b884a1c | 130 | pc.printf("* 1 - imposta ora orologio *\n"); |
Karrots3 | 2:e67f3b884a1c | 131 | pc.printf("* 2 - imposta ora pastiglia *\n"); |
Karrots3 | 2:e67f3b884a1c | 132 | pc.printf("* 3 - mostra settaggi *\n"); |
Karrots3 | 2:e67f3b884a1c | 133 | pc.scanf("%d", &s); |
Karrots3 | 2:e67f3b884a1c | 134 | switch(s) { |
Karrots3 | 2:e67f3b884a1c | 135 | case 1: |
Karrots3 | 2:e67f3b884a1c | 136 | pc.printf("Giorno (0..31)"); |
Karrots3 | 2:e67f3b884a1c | 137 | pc.scanf("%d", &time.date); |
Karrots3 | 2:e67f3b884a1c | 138 | pc.printf("Mese (1..12)"); |
Karrots3 | 2:e67f3b884a1c | 139 | pc.scanf("%d", &time.mon); |
Karrots3 | 2:e67f3b884a1c | 140 | pc.printf("Anno "); |
Karrots3 | 2:e67f3b884a1c | 141 | pc.scanf("%d", &time.year); |
Karrots3 | 2:e67f3b884a1c | 142 | pc.printf("Ore (0..23)"); |
Karrots3 | 2:e67f3b884a1c | 143 | pc.scanf("%d", &time.hour); |
Karrots3 | 2:e67f3b884a1c | 144 | pc.printf("Minuti (0..59)"); |
Karrots3 | 2:e67f3b884a1c | 145 | pc.scanf("%d", &time.min); |
Karrots3 | 2:e67f3b884a1c | 146 | pc.printf("Secondi (0..59)"); |
Karrots3 | 2:e67f3b884a1c | 147 | pc.scanf("%d", &time.sec); |
Karrots3 | 2:e67f3b884a1c | 148 | break; |
Karrots3 | 2:e67f3b884a1c | 149 | case 2: |
Karrots3 | 2:e67f3b884a1c | 150 | pc.printf("Orario pastiglia"); |
Karrots3 | 2:e67f3b884a1c | 151 | pc.scanf("%d", &orario_pastiglia); |
Karrots3 | 2:e67f3b884a1c | 152 | break; |
Karrots3 | 2:e67f3b884a1c | 153 | case 3: |
Karrots3 | 2:e67f3b884a1c | 154 | 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 | 2:e67f3b884a1c | 155 | break; |
Karrots3 | 2:e67f3b884a1c | 156 | } |
Karrots3 | 2:e67f3b884a1c | 157 | } |