electro
Dependencies: mbed QEI mbed-os KeypadLib TextLCD
electrocoagulador_final.cpp@0:6cde030caebb, 2019-03-01 (annotated)
- Committer:
- afsaavedram
- Date:
- Fri Mar 01 22:37:35 2019 +0000
- Revision:
- 0:6cde030caebb
- Child:
- 1:48c8726d6824
archivo final con control para electrocoagualcion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
afsaavedram | 0:6cde030caebb | 1 | #include "mbed.h" |
afsaavedram | 0:6cde030caebb | 2 | #include "keypad.h" |
afsaavedram | 0:6cde030caebb | 3 | #include "TextLCD.h" |
afsaavedram | 0:6cde030caebb | 4 | #include "stdlib.h" |
afsaavedram | 0:6cde030caebb | 5 | |
afsaavedram | 0:6cde030caebb | 6 | /*******************ELECTROVALVULAS********************/ |
afsaavedram | 0:6cde030caebb | 7 | |
afsaavedram | 0:6cde030caebb | 8 | DigitalOut E_1(D8); //Control de electrovalvula 1 |
afsaavedram | 0:6cde030caebb | 9 | DigitalOut E_2(D9); //Control de electrovalvula 2 |
afsaavedram | 0:6cde030caebb | 10 | DigitalOut E_3(D10); //Control de electrovalvula 3 |
afsaavedram | 0:6cde030caebb | 11 | DigitalOut E_4(D12); //Control de electrovalvula 4 |
afsaavedram | 0:6cde030caebb | 12 | AnalogIn sensor_nivel(A0); //Sensor nivel tanque 1 |
afsaavedram | 0:6cde030caebb | 13 | /*****************************************************/ |
afsaavedram | 0:6cde030caebb | 14 | |
afsaavedram | 0:6cde030caebb | 15 | /*******************INTERRUPCIONES********************/ |
afsaavedram | 0:6cde030caebb | 16 | |
afsaavedram | 0:6cde030caebb | 17 | InterruptIn button(USER_BUTTON); |
afsaavedram | 0:6cde030caebb | 18 | Timeout t_1; |
afsaavedram | 0:6cde030caebb | 19 | Timeout t_2; |
afsaavedram | 0:6cde030caebb | 20 | Timeout t_3; |
afsaavedram | 0:6cde030caebb | 21 | Timeout t_4; |
afsaavedram | 0:6cde030caebb | 22 | |
afsaavedram | 0:6cde030caebb | 23 | //tiempos de usuario |
afsaavedram | 0:6cde030caebb | 24 | float temp_user_1=0; //tiempo tope de electrocoagulacion |
afsaavedram | 0:6cde030caebb | 25 | float temp_user_2=0; //tiempo tope de reposo de la vinaza |
afsaavedram | 0:6cde030caebb | 26 | float temp_user_3=0; //tiempo tope de vaciado del agua en el tanque 2 |
afsaavedram | 0:6cde030caebb | 27 | float temp_user_4=0; //tiempo tope de vaciado de residuos en el tanque 2 |
afsaavedram | 0:6cde030caebb | 28 | |
afsaavedram | 0:6cde030caebb | 29 | |
afsaavedram | 0:6cde030caebb | 30 | |
afsaavedram | 0:6cde030caebb | 31 | |
afsaavedram | 0:6cde030caebb | 32 | /********************TECLADO Y LCD***********************/ |
afsaavedram | 0:6cde030caebb | 33 | |
afsaavedram | 0:6cde030caebb | 34 | // rs, e,d4,d5,d6,d7 |
afsaavedram | 0:6cde030caebb | 35 | TextLCD lcd(PC_8,PC_9,PC_10,PC_11,PC_12,PD_2); |
afsaavedram | 0:6cde030caebb | 36 | |
afsaavedram | 0:6cde030caebb | 37 | |
afsaavedram | 0:6cde030caebb | 38 | Keypad keypad(D3, D2, D1, D0, D7, D6, D5, D4); |
afsaavedram | 0:6cde030caebb | 39 | float num=0; |
afsaavedram | 0:6cde030caebb | 40 | char cadena[3]= {' ',' ',' '}; |
afsaavedram | 0:6cde030caebb | 41 | int llena=0; //verificar que la entrada es de 3 numeros |
afsaavedram | 0:6cde030caebb | 42 | |
afsaavedram | 0:6cde030caebb | 43 | |
afsaavedram | 0:6cde030caebb | 44 | /*********************FUNCIONES**************************/ |
afsaavedram | 0:6cde030caebb | 45 | |
afsaavedram | 0:6cde030caebb | 46 | void stop() //STOP |
afsaavedram | 0:6cde030caebb | 47 | { |
afsaavedram | 0:6cde030caebb | 48 | |
afsaavedram | 0:6cde030caebb | 49 | while(1) { |
afsaavedram | 0:6cde030caebb | 50 | lcd.cls(); |
afsaavedram | 0:6cde030caebb | 51 | } |
afsaavedram | 0:6cde030caebb | 52 | } |
afsaavedram | 0:6cde030caebb | 53 | |
afsaavedram | 0:6cde030caebb | 54 | bool electro_1() |
afsaavedram | 0:6cde030caebb | 55 | { |
afsaavedram | 0:6cde030caebb | 56 | E_1=!E_1; |
afsaavedram | 0:6cde030caebb | 57 | return E_1; |
afsaavedram | 0:6cde030caebb | 58 | } |
afsaavedram | 0:6cde030caebb | 59 | |
afsaavedram | 0:6cde030caebb | 60 | bool electro_2() |
afsaavedram | 0:6cde030caebb | 61 | { |
afsaavedram | 0:6cde030caebb | 62 | E_2=!E_2; |
afsaavedram | 0:6cde030caebb | 63 | return E_2; |
afsaavedram | 0:6cde030caebb | 64 | } |
afsaavedram | 0:6cde030caebb | 65 | |
afsaavedram | 0:6cde030caebb | 66 | bool electro_3() |
afsaavedram | 0:6cde030caebb | 67 | { |
afsaavedram | 0:6cde030caebb | 68 | E_3=!E_3; |
afsaavedram | 0:6cde030caebb | 69 | return E_3; |
afsaavedram | 0:6cde030caebb | 70 | } |
afsaavedram | 0:6cde030caebb | 71 | |
afsaavedram | 0:6cde030caebb | 72 | bool electro_4() |
afsaavedram | 0:6cde030caebb | 73 | { |
afsaavedram | 0:6cde030caebb | 74 | E_4=!E_4; |
afsaavedram | 0:6cde030caebb | 75 | return E_4; |
afsaavedram | 0:6cde030caebb | 76 | } |
afsaavedram | 0:6cde030caebb | 77 | /***********************MAIN***************************/ |
afsaavedram | 0:6cde030caebb | 78 | |
afsaavedram | 0:6cde030caebb | 79 | int main() |
afsaavedram | 0:6cde030caebb | 80 | { |
afsaavedram | 0:6cde030caebb | 81 | button.rise(&stop); |
afsaavedram | 0:6cde030caebb | 82 | keypad.enablePullUp(); |
afsaavedram | 0:6cde030caebb | 83 | wait(1); |
afsaavedram | 0:6cde030caebb | 84 | |
afsaavedram | 0:6cde030caebb | 85 | ini_1: |
afsaavedram | 0:6cde030caebb | 86 | lcd.locate(0,0); |
afsaavedram | 0:6cde030caebb | 87 | lcd.printf(" Control para\n"); |
afsaavedram | 0:6cde030caebb | 88 | lcd.locate(0,1); |
afsaavedram | 0:6cde030caebb | 89 | lcd.printf("electrocoagular\n"); |
afsaavedram | 0:6cde030caebb | 90 | wait(3); |
afsaavedram | 0:6cde030caebb | 91 | lcd.cls(); |
afsaavedram | 0:6cde030caebb | 92 | |
afsaavedram | 0:6cde030caebb | 93 | |
afsaavedram | 0:6cde030caebb | 94 | |
afsaavedram | 0:6cde030caebb | 95 | |
afsaavedram | 0:6cde030caebb | 96 | while(1) { |
afsaavedram | 0:6cde030caebb | 97 | lcd.locate(0,0); |
afsaavedram | 0:6cde030caebb | 98 | lcd.printf("t_1=%f",temp_user_1); |
afsaavedram | 0:6cde030caebb | 99 | lcd.locate(8,0); |
afsaavedram | 0:6cde030caebb | 100 | lcd.printf("t_2=%f",temp_user_2); |
afsaavedram | 0:6cde030caebb | 101 | lcd.locate(0,1); |
afsaavedram | 0:6cde030caebb | 102 | lcd.printf("t_3=%f",temp_user_3); |
afsaavedram | 0:6cde030caebb | 103 | lcd.locate(8,1); |
afsaavedram | 0:6cde030caebb | 104 | lcd.printf("t_4=%f",temp_user_4); |
afsaavedram | 0:6cde030caebb | 105 | |
afsaavedram | 0:6cde030caebb | 106 | char key = keypad.getKey(); |
afsaavedram | 0:6cde030caebb | 107 | // if(key=='A'){temp_user_1=10;} |
afsaavedram | 0:6cde030caebb | 108 | |
afsaavedram | 0:6cde030caebb | 109 | if(key=='A'){ |
afsaavedram | 0:6cde030caebb | 110 | } |
afsaavedram | 0:6cde030caebb | 111 | |
afsaavedram | 0:6cde030caebb | 112 | |
afsaavedram | 0:6cde030caebb | 113 | /* |
afsaavedram | 0:6cde030caebb | 114 | |
afsaavedram | 0:6cde030caebb | 115 | ini2: |
afsaavedram | 0:6cde030caebb | 116 | if(flag==0) { |
afsaavedram | 0:6cde030caebb | 117 | if(keypad.getKey()=='B') { |
afsaavedram | 0:6cde030caebb | 118 | cadena[0]=' '; |
afsaavedram | 0:6cde030caebb | 119 | cadena[1]=' '; |
afsaavedram | 0:6cde030caebb | 120 | cadena[2]=' '; |
afsaavedram | 0:6cde030caebb | 121 | llena=0; |
afsaavedram | 0:6cde030caebb | 122 | num=0; |
afsaavedram | 0:6cde030caebb | 123 | if(pos==4) { |
afsaavedram | 0:6cde030caebb | 124 | pos=1; |
afsaavedram | 0:6cde030caebb | 125 | } else { |
afsaavedram | 0:6cde030caebb | 126 | pos++; |
afsaavedram | 0:6cde030caebb | 127 | } |
afsaavedram | 0:6cde030caebb | 128 | } else if(keypad.getKey()=='A') { |
afsaavedram | 0:6cde030caebb | 129 | llena--; |
afsaavedram | 0:6cde030caebb | 130 | cadena[llena]=' '; |
afsaavedram | 0:6cde030caebb | 131 | num=strtod(cadena,NULL); |
afsaavedram | 0:6cde030caebb | 132 | } else if((keypad.getKey()=='0')||(keypad.getKey()=='1') |
afsaavedram | 0:6cde030caebb | 133 | ||(keypad.getKey()=='2')||(keypad.getKey()=='3') |
afsaavedram | 0:6cde030caebb | 134 | ||(keypad.getKey()=='4')||(keypad.getKey()=='5') |
afsaavedram | 0:6cde030caebb | 135 | ||(keypad.getKey()=='8')||(keypad.getKey()=='9')) { |
afsaavedram | 0:6cde030caebb | 136 | if(llena<3) { |
afsaavedram | 0:6cde030caebb | 137 | cadena[llena]=keypad.getKey(); |
afsaavedram | 0:6cde030caebb | 138 | num=strtod(cadena,NULL); |
afsaavedram | 0:6cde030caebb | 139 | llena++; |
afsaavedram | 0:6cde030caebb | 140 | } |
afsaavedram | 0:6cde030caebb | 141 | } else if(keypad.getKey()=='D') { |
afsaavedram | 0:6cde030caebb | 142 | lcd.cls(); //borra la pantalla |
afsaavedram | 0:6cde030caebb | 143 | lcd.printf("GUARDADOS!"); |
afsaavedram | 0:6cde030caebb | 144 | wait(1); |
afsaavedram | 0:6cde030caebb | 145 | lcd.cls(); |
afsaavedram | 0:6cde030caebb | 146 | lcd.printf("CONTROL INICIADO"); |
afsaavedram | 0:6cde030caebb | 147 | |
afsaavedram | 0:6cde030caebb | 148 | |
afsaavedram | 0:6cde030caebb | 149 | |
afsaavedram | 0:6cde030caebb | 150 | lcd.cls(); |
afsaavedram | 0:6cde030caebb | 151 | wait(2); |
afsaavedram | 0:6cde030caebb | 152 | |
afsaavedram | 0:6cde030caebb | 153 | ciclo_control: |
afsaavedram | 0:6cde030caebb | 154 | if(keypad.getKey()=='C') { |
afsaavedram | 0:6cde030caebb | 155 | temp_user_1=0; |
afsaavedram | 0:6cde030caebb | 156 | temp_user_2=0; |
afsaavedram | 0:6cde030caebb | 157 | temp_user_3=0; |
afsaavedram | 0:6cde030caebb | 158 | temp_user_4=0; |
afsaavedram | 0:6cde030caebb | 159 | llena=0; |
afsaavedram | 0:6cde030caebb | 160 | pos=1; |
afsaavedram | 0:6cde030caebb | 161 | flag=1; |
afsaavedram | 0:6cde030caebb | 162 | cadena[0]=' '; |
afsaavedram | 0:6cde030caebb | 163 | cadena[1]=' '; |
afsaavedram | 0:6cde030caebb | 164 | cadena[2]=' '; |
afsaavedram | 0:6cde030caebb | 165 | goto ini_1; |
afsaavedram | 0:6cde030caebb | 166 | } |
afsaavedram | 0:6cde030caebb | 167 | |
afsaavedram | 0:6cde030caebb | 168 | } |
afsaavedram | 0:6cde030caebb | 169 | |
afsaavedram | 0:6cde030caebb | 170 | if(pos==1){ |
afsaavedram | 0:6cde030caebb | 171 | temp_user_1=num; |
afsaavedram | 0:6cde030caebb | 172 | lcd.locate(3,0);lcd.printf(" "); |
afsaavedram | 0:6cde030caebb | 173 | lcd.locate(3,0);lcd.printf("%f",t_1); |
afsaavedram | 0:6cde030caebb | 174 | } |
afsaavedram | 0:6cde030caebb | 175 | else if(pos==2){ |
afsaavedram | 0:6cde030caebb | 176 | temp_user_2=num; |
afsaavedram | 0:6cde030caebb | 177 | lcd.locate(11,0);lcd.printf(" "); |
afsaavedram | 0:6cde030caebb | 178 | lcd.locate(11,0);lcd.printf("%f",t_2); |
afsaavedram | 0:6cde030caebb | 179 | } |
afsaavedram | 0:6cde030caebb | 180 | else if(pos==3){ |
afsaavedram | 0:6cde030caebb | 181 | temp_user_3=num; |
afsaavedram | 0:6cde030caebb | 182 | lcd.locate(3,1);lcd.printf(" "); |
afsaavedram | 0:6cde030caebb | 183 | lcd.locate(3,1);lcd.printf("%f",t_3); |
afsaavedram | 0:6cde030caebb | 184 | } |
afsaavedram | 0:6cde030caebb | 185 | else if(pos==4){ |
afsaavedram | 0:6cde030caebb | 186 | temp_user_4=num; |
afsaavedram | 0:6cde030caebb | 187 | lcd.locate(11,1);lcd.printf(" "); |
afsaavedram | 0:6cde030caebb | 188 | lcd.locate(11,1);lcd.printf("%f",t_4); |
afsaavedram | 0:6cde030caebb | 189 | } |
afsaavedram | 0:6cde030caebb | 190 | |
afsaavedram | 0:6cde030caebb | 191 | flag=1; |
afsaavedram | 0:6cde030caebb | 192 | goto ini2;} |
afsaavedram | 0:6cde030caebb | 193 | |
afsaavedram | 0:6cde030caebb | 194 | */ |
afsaavedram | 0:6cde030caebb | 195 | |
afsaavedram | 0:6cde030caebb | 196 | |
afsaavedram | 0:6cde030caebb | 197 | |
afsaavedram | 0:6cde030caebb | 198 | |
afsaavedram | 0:6cde030caebb | 199 | }//termina while de main |
afsaavedram | 0:6cde030caebb | 200 | }//termina main |