CARLO TARALLO
/
time_Vibra
vibratime
Diff: main.cpp
- Revision:
- 8:281ad9672a53
- Parent:
- 7:c336250d2897
- Child:
- 9:a3c4335a1e09
--- a/main.cpp Fri Mar 13 15:44:05 2020 +0000 +++ b/main.cpp Wed Mar 25 14:14:55 2020 +0000 @@ -15,33 +15,202 @@ */ #include "mbed.h" - long dataUnix = 0; int settore = 0; -char Source[50]="working with strings is fun 0123456789 9876543210"; -char Destination[50]; -int pos,len; +int ore = 0; +int minuti = 0; + + char mon[30]="Mon"; + char tue[30]="Tue"; + char wed[30]="Wed"; + char thu[30]="Thu"; + char fri[30]="Fri"; + char sat[30]="Sat"; + char sun[30]="Sun"; + +char giorno1[4]="Sun"; +char ora1[3]="04"; +char min1[3]="31"; +char am1[3]="AM"; +char S1[2]="5"; +char giorno2[4]="Sun"; +char ora2[3]="08"; +char min2[3]="20"; +char am2[3]="PM"; +char S2[2]="3"; +char giorno3[4]="Mon"; +char ora3[3]="04"; +char min3[3]="33"; +char am3[3]="AM"; +char S3[2]="5"; +char giorno4[4]="Tue"; +char ora4[3]="04"; +char min4[3]="36"; +char am4[3]="AM"; +char S4[2]="3"; +char giorno5[4]="Tue"; +char ora5[3]="05"; +char min5[3]="20"; +char am5[3]="PM"; +char S5[2]="5"; +char giorno6[4]="Fri"; +char ora6[3]="05"; +char min6[3]="10"; +char am6[3]="AM"; +char S6[2]="2"; +char giorno7[4]="Fri"; +char ora7[3]="06"; +char min7[3]="31"; +char am7[3]="PM"; +char S7[2]="5"; + +char am[3]="AM"; +char pm[3]="PM"; +char ampm[3]; +char ora[3]; +char minu[3]; DigitalIn vibra(D7); -//AnalogIn vibration_Sensor(A5); int present_condition = 0; int previous_condition = 0; -//float present_condition = 0; -//float previous_condition = 0; + +int step_speed = 1200 ; // set default motor speed +int numstep = 514 ; // defines full turn of 360 degree +//you might want to calibrate this value according to your motor +int statomax =7; +int kmax = 8; +int stato; + + + +DigitalOut IN1(D8); +DigitalOut IN2(D9); +DigitalOut IN3(D10); +DigitalOut IN4(D11); + +const int MotoreOFF = 99; // motore spento + + + +void Uscita( int i4,int i3,int i2,int i1) +{ + if (i1==1) IN1=1; else IN1=0; + if (i2==1) IN2=1; else IN2=0; + if (i3==1) IN3=1; else IN3=0; + if (i4==1) IN4=1; else IN4=0; +/* + if (i1==1) digitalWrite(IN1,HIGH); else digitalWrite(IN1,LOW); + if (i2==1) digitalWrite(IN2,HIGH); else digitalWrite(IN2,LOW); + if (i3==1) digitalWrite(IN3,HIGH); else digitalWrite(IN3,LOW); + if (i4==1) digitalWrite(IN4,HIGH); else digitalWrite(IN4,LOW); + */ +} + + + +void EseguiPasso(int stato) +{ +int i1,i2,i3,i4; + + switch ( stato ) + {// vedi tabella nel pdf del motore passo passo + case 0: Uscita(0,0,0,1); break; + case 1: Uscita(0,0,1,1); break; + case 2: Uscita(0,0,1,0); break; + case 3: Uscita(0,1,1,0); break; + case 4: Uscita(0,1,0,0); break; + case 5: Uscita(1,1,0,0); break; + case 6: Uscita(1,0,0,0); break; + case 7: Uscita(1,0,0,1); break; + case 8: Uscita(0,0,0,1); break; + case 9: Uscita(0,0,1,1); break; + case 10: Uscita(0,0,1,0); break; + case 11: Uscita(0,1,1,0); break; + case 12: Uscita(0,1,0,0); break; + case 13: Uscita(1,1,0,0); break; + case 14: Uscita(1,0,0,0); break; +// case 7: Uscita(1,0,0,1); break; + case MotoreOFF: //OFF + Uscita(0,0,0,0); break; + } + wait_ms(1); + // delay(1); //ritardo almeno 1 mS +} -void substring(char *s,char *d,int pos,int len) { -//usage: substring(Source,Destination,pos,len); - - char *t; +void RitardoAccensione() +{ //attesa prima di attivare il motore + EseguiPasso(MotoreOFF); + for(int i=0; i<10; i++) + { +// digitalWrite(13,HIGH); +// wait_ms(250); + // delay(250); +// digitalWrite(13,LOW); +// wait_ms(250); + // delay(250); + } +} + + +void posizSettore() +{ //attesa prima di attivare il motore + stato=0; //inizio da uno stato arbitrario + + +if (kmax>0) +{ + stato=0; //inizio da uno stato arbitrario + + for(int k=0; k<kmax; k++) //Rotazione Oraria + // for(int k=0; k<4; k++) //Rotazione Oraria + { + for (int i=0; i<numstep; i++) //45 gradi a ciclo + // for (int i=0; i<514; i++) //45 gradi a ciclo +// for (int i=0; i<1024; i++) //90 gradi a ciclo + { + EseguiPasso(stato); + stato=stato+1; // avanza nella tabella +/* printf("Stato : \r\n"); + printf("%d\r\n",stato); + printf("k : \r\n"); + printf("%d\r\n",k); + */ + if ((stato)>statomax) + { + stato=0; + // if ((stato)>7) stato=0; + } + EseguiPasso(MotoreOFF); + // wait_ms(500); // pausa di mezzo secondo + } + wait_ms(1000); // pausa di 1 secondo + } + for(int k=0; k<kmax; k++) //Rotazione AntiOraria +// for(int k=0; k<4; k++) //Rotazione AntiOraria + { + for (int i=0; i<numstep; i++) //45 gradi a ciclo +// for (int i=0; i<514; i++) //45 gradi a ciclo +// for (int i=0; i<1024; i++) //90 gradi a ciclo + { + EseguiPasso(stato); + stato=stato-1; //torna indietro nella tabella + /* printf("Stato : \r\n"); + printf("%d\r\n",stato); + printf("k : \r\n"); + printf("%d\r\n",k); + */ + if ((stato)<0) + { + stato=statomax; + // if ((stato)<0) stato=7; + } + EseguiPasso(MotoreOFF); + // wait_ms(500); + } + wait_ms(1000); + } + } - s=s+(pos-1); - t=s+len; - while (s!=t) { - *d=*s; - s++; - d++; - } - *d='\0'; } int main() { @@ -51,31 +220,17 @@ scanf("%li", &dataUnix); printf("%li\n",dataUnix); - printf("Inserisci numero Settore \r\n"); - scanf("%li", &settore); - printf("%li\n",dataUnix); +// set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 - -// set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 - // set_time(1583715900); // Set RTC time to Wed, 28 Oct 2009 11:35:37 set_time(dataUnix); // Set RTC time to Wed, 28 Oct 2009 11:35:37 while (true) { previous_condition = present_condition; - present_condition = vibra.read(); - // present_condition = vibration_Sensor.read(); - printf(" VALORE : %d\r\n", present_condition); - // printf(" VALORE : %1.3f\r\n", present_condition); + present_condition = vibra.read(); + printf(" VALORE : %d\r\n", present_condition); if (previous_condition != present_condition) { - // if (present_condition == 1) { - printf(" Pillola caduta : %d\r\n", present_condition); - - // printf("Pillola caduta \n"); - - } - // else { - // printf("Pillola NON caduta \n"); - // } + printf(" Pillola caduta : %d\r\n", present_condition); + } time_t seconds = time(NULL); @@ -84,20 +239,10 @@ printf("Time as a basic string = %s", ctime(&seconds)); + char bufH[15]; char buf[3]; - - - - // seconds = time(NULL); // get current time from mbed RTC - strftime(buf,3, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); - - char mon[30]="Mon"; - char tue[30]="Tue"; - char wed[30]="Wed"; - char thu[30]="Thu"; - char fri[30]="Fri"; - char sat[30]="Sat"; - char sun[30]="Sun"; + + strftime(buf,3, "%a,%d %m %Y.%H:%M:%S\r", localtime(&seconds)); @@ -131,39 +276,58 @@ { printf("Ho letto DOMENICA \r\n"); } - - -// Sub‐Strings -char *buff = ctime(&seconds); -//char *buff = "Hello World"; -char* substr; -strncpy(substr, buff+7, 5); //begin index: 7 substring length: 5 + + char buffer[32]; + strftime(buffer, 8, "%I:%M %p\n", localtime(&seconds)); + // printf("Time as a custom formatted string = %s\r\n", buffer); + ora[0] = buffer[0]; + ora[1] = buffer[1]; + minu[0] = buffer[3]; + minu[1] = buffer[4]; + + printf("ora = %s\r\n", ora); + printf("minuti = %s\r\n", minu); - printf("MESE = %s", substr); - - // int pos,len; - /* - usbUART.printf("----------------------------------------------------------\r\n"); - usbUART.printf(" substring demo \r\n"); - usbUART.printf("----------------------------------------------------------\r\n"); - usbUART.printf("source: %s\r\n", Source); - usbUART.printf("----------------------------------------------------------\r\n"); - printf("input the start position, tap enter, input length, tap enter "); - scanf("%d%d",&pos,&len); - printf("\n\n"); - - pos=1; - len=3; - - substring(Source,Destination,pos,len); - Source = ctime(&seconds); - printf("s= %s\n\r", Source); - printf("d= %s\n\r", Destination); -*/ - char buffer[32]; - strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); - printf("Time as a custom formatted string = %s", buffer); - - // wait(1); + ampm[0] = buffer[6]; + ampm[1] = buffer[7]; + + + printf("Mattina/Pomeriggio= %s\r\n", ampm); + if(strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0) + { + printf("è ora medicina e minuto prima MEDICINA \r\n"); + } + + + if(strncmp(buf, giorno1, 3)==0 and strncmp(ora, ora1, 2)==0 and strncmp(minu, min1, 2)==0 and strncmp(ampm, am1, 2)==0) + { + printf("Vai a settore S1 \r\n"); + } + + + if(strncmp(ora, ora2, 2)==0 and strncmp(minu, min2, 2)==0) + { + printf("è ora e minuto Seconda MEDICINA \r\n"); + } + + if(strncmp(ora, ora1, 2)==0) + { + printf("è ora medicina 1 \r\n"); + } + + if(strncmp(minu, min1, 2)==0) + { + printf("è minuto medicina 1 \r\n"); + } + + if(strncmp(ampm, am, 2)==0) + { + printf("è mattino \r\n"); + } + if(strncmp(ampm, pm, 2)==0) + { + printf("è pomeriggio \r\n"); + } + } }