menu con motor dc, motor paso, servo, keypad y lcd
Dependencies: mbed Servo TextLCD Keypad
Revision 0:df9033dc3e2e, committed 2021-02-03
- Comitter:
- SantiagoE
- Date:
- Wed Feb 03 18:58:27 2021 +0000
- Commit message:
- hola
Changed in this revision
diff -r 000000000000 -r df9033dc3e2e Keypad.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Keypad.lib Wed Feb 03 18:58:27 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/grantphillips/code/Keypad/#4bbd88022a6f
diff -r 000000000000 -r df9033dc3e2e Servo.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Wed Feb 03 18:58:27 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/jdenkers/code/Servo/#352133517ccc
diff -r 000000000000 -r df9033dc3e2e TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Wed Feb 03 18:58:27 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r df9033dc3e2e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Feb 03 18:58:27 2021 +0000 @@ -0,0 +1,471 @@ +#include "mbed.h" +#include "Keypad.h" +#include "TextLCD.h" +#include "Servo.h" +//StepperMotorUni paso(D0,D1,D2,D3); +BusOut paso(D0,D1,D2,D3); +int posi; +int violet=5; +int vector[4]= { + 0b1000, + 0b0100, + 0b0010, + 0b0001, +}; +Servo Servo1(D4);//digital +PwmOut motdc1(D8); +PwmOut motdc2(D9); +PwmOut pwm1(D12); +DigitalOut led(LED1); +AnalogIn potenciometro(A0); +AnalogIn lm(A1); +TextLCD lcd(PTB8, PTB9,PTB10,PTB11,PTE2,PTE3, TextLCD::LCD16x2); +Keypad teclado(PTC4,PTC3,PTC0,PTC7,PTC11,PTC10,PTC6,PTC5); +Ticker porc; +int num_pasos=0; +char key; +//int x=0,m=0,a=0,g=0,ser=0,dirs=0,dirp=0,pas=0,unid,dec,unid1,dec1,servo,grados; +int a,b,c,j=0,t1,t2,tt,pp; +int al,on,off,mdc,mdct,ppt,ppd,contm,sert; +float porcentaje1,porcentaje2,l; +void Pin() +{ + l=lm.read(); + l=(l*3)*100; + motdc1=porcentaje1; + motdc2=porcentaje2; + +} +int main() +{ + porc.attach(&Pin,0.002); + lcd.cls(); + lcd.printf("Edward \n20181573088"); + wait(4.5); +casa: + wait(0.5); + lcd.cls(); + lcd.printf("1.manual 2.auto"); + //definición de velocidad paso a paso y periodo del servo + //paso.set_pps(600); + Servo1.Enable(1500,20000);//en la mitad la posición + while(1){ + while(1) { + key=teclado.ReadKey(); + if(key!='\0') { + if(key=='1') { + wait(1); + lcd.cls(); + lcd.printf("Manual"); + goto manual; + } else if(key=='2') { + wait(1); + lcd.cls(); + lcd.printf("valor del servo"); + goto datos; + } + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } + while(1) { +manual: + lcd.cls(); + lcd.printf("Manual"); + wait(0.5); + led=1; + key=teclado.ReadKey(); + if(key!='\0') { + //Manual temperatura + if(key=='1') { + lcd.cls(); + lcd.printf("temperatura"); + goto manualtemperatura; + //Manual alarma + }else if(key=='2') { + lcd.cls(); + lcd.printf("alarma"); + goto manualalarma; + //Manual motor DC + }else if(key=='3') { + lcd.cls(); + lcd.printf("Motor DC\n1.Izq 2.Dere"); + wait(0.5); + while(1) { + key=teclado.ReadKey(); + if(key != '\0') { + if(j==0){ + mdct=key; + j=j+1; + wait(1); + lcd.cls(); + lcd.printf("Velocidad"); + }else if(j==1){ + lcd.locate(0,1); + lcd.printf("%c",key); + a=(key-'0')*10; + j=j+1; + } else if(j==2) { + lcd.locate(1,1); + lcd.printf("%c",key); + b=(key-'0'); + mdc=a+b; + wait(1); + lcd.cls(); + lcd.printf("%d",mdc); + j=0; + goto manualmdc; + } + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } + //Manual paso a paso + }else if(key=='4') { + lcd.cls(); + lcd.printf("Motor PP\n1.Izq 2.Dere"); + wait(0.5); + while(1) { + key=teclado.ReadKey(); + if(key != '\0') { + if(j==0){ + ppd=key; + j=j+1; + wait(1); + lcd.cls(); + lcd.printf("num pasos"); + }else if(j==1){ + lcd.locate(0,1); + lcd.printf("%c",key); + a=(key-'0')*10; + j=j+1; + } else if(j==2) { + lcd.locate(1,1); + lcd.printf("%c",key); + b=(key-'0'); + ppt=a+b; + wait(1); + lcd.cls(); + lcd.printf("%d",ppt); + j=0; + goto manualpp; + } + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } + //Manual servo + }else if(key=='5') { + lcd.cls(); + lcd.printf("servo\nangulo"); + wait(0.5); + while(1) { + key=teclado.ReadKey(); + if(key != '\0') { + if(j==0){ + lcd.locate(0,1); + lcd.printf("%c",key); + a=(key-'0')*10; + j=j+1; + } else if(j==1) { + lcd.locate(1,1); + lcd.printf("%c",key); + b=(key-'0'); + sert=a+b; + wait(1); + lcd.cls(); + lcd.printf("%d",sert); + j=0; + goto manualservo; + } + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } + //Menu principal + } else if(key=='*') { + paso=0b000; + Servo1.SetPosition(500);//0 grados + goto casa; + } + } + while(key != '\0') { + + key=teclado.ReadKey(); + } + + } +//#1 + while(1) { +manualtemperatura: + lcd.cls(); + lcd.printf("la temp es: \n%f",l); + key=teclado.ReadKey(); + if(key != '\0') { + if(key=='1'){ + goto manual; + }else if(key=='2'){ + goto casa; + } + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } +//#2 + while(1) { +manualalarma: + key=teclado.ReadKey(); + if(key != '\0') { + if(key=='1'){ + on=1; + off=0; + }else if(key=='2'){ + off=1; + on=0; + }else if(key=='3'){ + goto manual; + }else if(key=='4'){ + goto casa; + } + } + if(on==1){ + for (float i; i<1.0; i=i+0.1) { + pwm1=i; + } + }else if(off==1){ + pwm1=0; + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } +//#3 + while(1) { +manualmdc: + key=teclado.ReadKey(); + if(key != '\0') { + if(key=='1'){ + goto manual; + }else if(key=='2'){ + goto casa; + } + } + if(mdct==1){ + porcentaje1=mdc*0.001; + porcentaje2=0; + }else if(mdct==2){ + porcentaje2=mdc*0.01; + porcentaje1=0; + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } +//#4 + while(1) { +manualpp: + key=teclado.ReadKey(); + if(key != '\0') { + if(key=='1'){ + goto manual; + }else if(key=='2'){ + goto casa; + } + } + if(ppd==1){ + //num_pasos=0; + while(num_pasos<=(ppt*10)){ + paso=vector[posi]; + wait(0.002); + posi++; + if(posi==5) { + posi=0; + num_pasos++; + } + } + }else if(ppd==2){ + //num_pasos=0; + while(num_pasos<=(ppt*10)){ + paso=vector[violet]; + wait(0.002); + violet--;; + if(violet==0) { + violet=5; + num_pasos++; + } + } + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } +//#5 + while(1) { + manualservo: + key=teclado.ReadKey(); + if(key != '\0') { + if(key=='1'){ + goto manual; + }else if(key=='2'){ + goto casa; + } + } + int Val=500+((1000/90)*sert); + for(int i=500; i<Val; i+=25) { + Servo1.SetPosition(i); + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } + + while(1) { +datos: + key=teclado.ReadKey(); + if(key!='\0') { + if(j==0) { + lcd.locate(0,1); + lcd.printf("%c",key); + a=(key-'0')*10; + j=j+1; + } else if(j==1) { + lcd.locate(1,1); + lcd.printf("%c",key); + b=(key-'0'); + sert=a+b; + wait(1); + lcd.cls(); + lcd.printf("direc mot\n1.Izq 2.Dere"); + j=j+1; + } else if(j==2) { + if (key=='1') { + mdct=1; + j=j+1; + } else if(key=='2') { + mdct=2; + j=j+1; + } + wait(1); + lcd.cls(); + lcd.printf("vel mot"); + }else if(j==3) { + lcd.locate(0,1); + lcd.printf("%c",key); + a=(key-'0')*10; + j=j+1; + } else if(j==4) { + lcd.locate(1,1); + lcd.printf("%c",key); + b=(key-'0'); + mdc=a+b; + wait(1); + lcd.cls(); + lcd.printf("direc pp\n1.Izq 2.Dere"); + j=j+1; + }else if(j==5) { + if (key=='1') { + ppd=1; + j=j+1; + } else if(key=='2') { + ppd=2; + j=j+1; + } + wait(1); + lcd.cls(); + lcd.printf("pasos pp"); + }else if(j==6) { + lcd.locate(0,1); + lcd.printf("%c",key); + a=(key-'0')*10; + j=j+1; + } else if(j==7) { + lcd.locate(1,1); + lcd.printf("%c",key); + b=(key-'0'); + ppt=a+b; + wait(1); + lcd.cls(); + lcd.printf("set point"); + j=j+1; + } else if (j==8) { + lcd.locate(0,1); + lcd.printf("%c",key); + t1=(key-'0')*10; + j=j+1; + wait(1); + } else if (j==9) { + lcd.locate(1,1); + lcd.printf("%c",key); + t2=(key-'0'); + tt=t1+t2; + j=0; + wait(1); + goto automatico; + } + } + while(key != '\0') { + key=teclado.ReadKey(); + } + } + while(1) { +automatico: + lcd.cls(); + lcd.printf("la temp es: \n%f",l); + if (l<tt) { + pwm1=0; + Servo1.SetPosition(500); + porcentaje1=0; + porcentaje2=0; + paso=0b0000; + } + if(l>tt) { + //automático motor dc + if(mdct==1){ + porcentaje1=mdc*0.001; + porcentaje2=0; + }else if(mdct==2){ + porcentaje2=mdc*0.01; + porcentaje1=0; + } + //automático paso a paso + if(ppd==1){ + //num_pasos=0; + while(num_pasos<=(ppt*10)){ + paso=vector[posi]; + wait(0.002); + posi++; + if(posi==5) { + posi=0; + num_pasos++; + } + } + }else if(ppd==2){ + //num_pasos=0; + while(num_pasos<=(ppt*10)){ + paso=vector[violet]; + wait(0.002); + violet--;; + if(violet==0) { + violet=5; + num_pasos++; + } + } + } + //grados del servo + int Val=500+((1000/90)*sert); + for(int i=500; i<Val; i+=25) { + Servo1.SetPosition(i); + } + //Bocina + for (float i; i<1.0; i=i+0.1) { + pwm1=i; + } + } + } + } +}
diff -r 000000000000 -r df9033dc3e2e mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Feb 03 18:58:27 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file