Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-os KeypadLib TextLCD
electrocoagulador_final.cpp
00001 #include "mbed.h" 00002 #include "keypad.h" 00003 #include "TextLCD.h" 00004 #include "stdlib.h" //opcional 00005 00006 /*******************ELECTROVALVULAS********************/ 00007 00008 DigitalOut E_1(D8,0); //Control de electrovalvula 1 00009 DigitalOut E_2(D9,0); //Control de electrovalvula 2 00010 DigitalOut E_3(D10,0); //Control de electrovalvula 3 00011 DigitalOut E_4(D12,0); //Control de electrovalvula 4 00012 AnalogIn sensor_level(A0); //Sensor nivel tanque 1 00013 PwmOut motor(PA_5); //variable temporal para el motor (se cambiará después) 00014 /*****************************************************/ 00015 00016 00017 00018 /*******************INTERRUPCIONES********************/ 00019 00020 InterruptIn button(USER_BUTTON); 00021 Ticker check_level; 00022 Ticker up; 00023 Ticker down; 00024 00025 Timeout t_1; 00026 Timeout t_2; 00027 Timeout t_3; 00028 Timeout t_4; 00029 00030 //tiempos de usuario 00031 int temp_user_1=5; //tiempo tope de electrocoagulacion 00032 int temp_user_2=5; //tiempo tope de reposo de la vinaza 00033 int temp_user_3=5; //tiempo tope de vaciado del agua en el tanque 2 00034 int temp_user_4=5; //tiempo tope de vaciado de residuos en el tanque 2 00035 int pwm=5; 00036 00037 00038 //timers 00039 Timer timer_1; 00040 Timer timer_2; 00041 Timer timer_3; 00042 00043 /********************TECLADO Y LCD***********************/ 00044 00045 // rs, e,d4,d5,d6,d7 00046 TextLCD lcd(PC_8,PC_9,PC_10,PC_11,PC_12,PD_2); 00047 00048 00049 Keypad keypad(D3, D2, D1, D0, D7, D6, D5, D4); 00050 float num=0; 00051 char cadena[3]= {' ',' ',' '}; 00052 int llena=0; //verificar que la entrada es de 3 numeros 00053 int blinker = 1; 00054 00055 /*********************FUNCIONES**************************/ 00056 00057 void stop() //STOP 00058 { 00059 while(1) { 00060 lcd.cls(); 00061 lcd.printf(" STOP!"); 00062 lcd.locate(0,1); 00063 lcd.printf(" PLEASE RESET"); 00064 wait_ms(150); 00065 } 00066 } 00067 00068 void level() 00069 { 00070 if(sensor_level>=3) { 00071 E_1=0; 00072 } 00073 } 00074 00075 void electro_1() 00076 { 00077 E_1=!E_1; 00078 } 00079 00080 void electro_2() 00081 { 00082 E_2=!E_2; 00083 } 00084 00085 void electro_3() 00086 { 00087 E_3=!E_3; 00088 } 00089 00090 void electro_4() 00091 { 00092 E_4=!E_4; 00093 } 00094 00095 void printLCD(){ 00096 while(1){ 00097 lcd.cls(); 00098 lcd.locate(0,0); 00099 lcd.printf("t1=%d",temp_user_1); 00100 lcd.locate(6,0); 00101 lcd.printf("t2=%d",temp_user_2); 00102 lcd.locate(0,1); 00103 lcd.printf("t3=%d",temp_user_3); 00104 lcd.locate(6,1); 00105 lcd.printf("t4=%d",temp_user_4); 00106 lcd.locate(12,0); 00107 lcd.printf("PWM"); 00108 lcd.locate(12,1); 00109 lcd.printf("%d",pwm); 00110 wait_ms(350); 00111 switch(blinker){ 00112 case 1: 00113 lcd.locate(0,0); 00114 lcd.printf("t1= ",temp_user_1); break; 00115 case 2: 00116 lcd.locate(6,0); 00117 lcd.printf("t2= ",temp_user_2); break; 00118 case 3: 00119 lcd.locate(0,1); 00120 lcd.printf("t3= ",temp_user_3); break; 00121 case 4: 00122 lcd.locate(6,1); 00123 lcd.printf("t4= ",temp_user_4); break; 00124 case 5: 00125 lcd.locate(12,1); 00126 lcd.printf(" "); 00127 default: ; break; 00128 } 00129 wait_ms(350); 00130 } 00131 } 00132 00133 int getNum(){ 00134 while(1){ 00135 char key = keypad.getKey(); 00136 switch(key) { 00137 case '0': return 0; 00138 case '1': return 1; 00139 case '2': return 2; 00140 case '3': return 3; 00141 case '4': return 4; 00142 case '5': return 5; 00143 case '6': return 6; 00144 case '7': return 7; 00145 case '8': return 8; 00146 case '9': return 9; 00147 case 'A': 00148 blinker++; 00149 if(blinker==6) blinker=1; return -1; 00150 default: ; break; 00151 } 00152 wait_ms(100); 00153 } 00154 } 00155 00156 /***********************MAIN***************************/ 00157 00158 int main() 00159 { 00160 button.rise(&stop); 00161 keypad.enablePullUp(); 00162 wait(1); 00163 lcd.locate(0,0); 00164 lcd.printf(" Control para\n"); 00165 lcd.locate(0,1); 00166 lcd.printf("electrocoagular\n"); 00167 wait(1.5); 00168 lcd.cls(); 00169 int a=0; 00170 int b=0; 00171 int c=0; 00172 00173 Thread lcdprint; 00174 lcdprint.start(printLCD); 00175 00176 while(1) { 00177 setvalue: 00178 a=100*getNum(); 00179 wait_ms(250); 00180 if(a<0)goto setvalue; 00181 b=10*getNum(); 00182 wait_ms(250); 00183 if(b<0)goto setvalue; 00184 c=getNum(); 00185 wait_ms(250); 00186 if(c<0)goto setvalue; 00187 00188 switch(blinker){ 00189 case 1: 00190 temp_user_1=a+b+c; break; 00191 case 2: 00192 temp_user_2=a+b+c; break; 00193 case 3: 00194 temp_user_3=a+b+c; break; 00195 case 4: 00196 temp_user_4=a+b+c; break; 00197 case 5: 00198 pwm=a+b+c; break; 00199 } 00200 wait_ms(150); 00201 00202 }//termina while de main 00203 }//termina main
Generated on Sun Jul 17 2022 19:08:09 by
