Reyper V3.0
Dependencies: mbed mbed-rtos DebounceIn NEMA-FastPWM
main.cpp
- Committer:
- FelipeVR
- Date:
- 2019-04-16
- Revision:
- 7:bcb8bbde80ca
- Parent:
- 6:0e648727740b
File content as of revision 7:bcb8bbde80ca:
#include "mbed.h" #include "FastPWM.h" #include "DebounceIn.h" #include "rtos.h" Serial Pc(P0_19, P0_18); //Ev1=p12, EV2 = p6, LG = p15, LW = p16, LB = p17, LR = p18, Out = p5, Sb = p11, Sr = p19, Sw = p22, In = p7, P1 = p20 DigitalOut Led1(p25); DigitalOut Dir1(p15);//LG DigitalOut Dir2(p16);//LW FastPWM Pul1(p6);//EV2 FastPWM Pul2(p5);//Out DigitalOut LB(p17);//LB DigitalOut LR(p18);//LR DigitalOut En1(p12);//EV1 DebounceIn FDC1(p22);//SW DebounceIn FDC2(p19);//SR DebounceIn Alerta(p7);//In DigitalIn SG(p11);//SB float t1=.00019; char fcs[10],fis[10],stps[10],fas[10],tes[10],chsum[10]; int FC = 500, FI = 300, STP = 1600, FA = 250, TE= 3, inicio = 0, SUMAMBED = 0; char K[1000]; int contadorRojo_def = 0; void SLV (void const *args) { while (true) { if (Pc.readable()) { Pc.scanf("%s", &K); Pc.printf("%s\n",K); strcpy(fcs, strtok(K , ",")); strcpy(fis, strtok(NULL , ",")); strcpy(stps, strtok(NULL, ",")); strcpy(fas, strtok(NULL, ",")); strcpy(tes, strtok(NULL, ",")); strcpy(chsum, strtok(NULL, ",/n")); SUMAMBED = atoi(fcs) + atoi(fis) + atoi(stps) + atoi(fas) + atoi(tes); if(SUMAMBED == atoi(chsum)) { FC = atoi(fcs);FI = atoi(fis); STP = atoi(stps); FA = atoi(fas);TE = atoi(tes); } } //Pc.printf("%i,%i,%i,%i,%i,%i\n",FC,FI,STP,FA,TE,SUMAMBED); } } int main() { Pc.baud(9600); //Thread Uno(SLV); En1=0; wait(2); Led1=0; En1=1; wait(2); Pul1.period_us(700); Pul1.write(.5); Pul2.period_us(700); Pul2.write(.5); Pul1=0; Pul2=0; while (1) { Led1=1; if (Pc.readable()) { Pc.scanf("%s", &K); //Pc.printf("%s\n",K); strcpy(fcs, strtok(K , ",")); strcpy(fis, strtok(NULL , ",")); strcpy(stps, strtok(NULL, ",")); strcpy(fas, strtok(NULL, ",")); strcpy(tes, strtok(NULL, ",")); strcpy(chsum, strtok(NULL, ",/n")); SUMAMBED = atoi(fcs) + atoi(fis) + atoi(stps) + atoi(fas) + atoi(tes); if(SUMAMBED == atoi(chsum)) { FC = atoi(fcs);FI = atoi(fis); STP = atoi(stps); FA = atoi(fas);TE = atoi(tes); } inicio = 1; } Pc.printf("1"); if(SG==0 || inicio == 1){ inicio = 1; LR=1; LB=0; ///////// Cierre de molde ///////////// Pul2.period_us(FC); while(FDC1==0) {Dir2=0;Pul2=0.5;} Pul2=0; //////// Inyeccion Plastico /////////// Pul1.period_us(FI); while(1) {Dir1=0;Pul1=0.5;wait_us(STP*FI);break;}Pul1=0; /////////Pausa ///////////////// wait(TE); ///////// Apertura ///////////// Pul2.period_us(FA); while(FDC2 == 0) { Dir2=1; Pul2=0.5; }Pul2=0; wait(.5); //////////////////////////////////// } if (Alerta == 0) //// Aqui va el boton rojo, hay que checar que sea ese. { Pc.printf("Terminar secuencia...\n\r"); LR = 0; LB = 1; inicio = 0; wait(1); contadorRojo_def ++; LR = 1; LB = 0; } if (contadorRojo_def >= 3 ) { Pul1.period_us(FI); while(1) {Dir1=0;Pul1=0.5;wait_us(STP*FI);break;}Pul1=0; contadorRojo_def = 0; } LB = 1; LR = 0; } }