electro
Dependencies: mbed mbed-os KeypadLib TextLCD
electrocoagulador_final.cpp@3:a4994da37d1f, 2019-03-02 (annotated)
- Committer:
- afsaavedram
- Date:
- Sat Mar 02 04:29:55 2019 +0000
- Revision:
- 3:a4994da37d1f
- Parent:
- 2:4b27d3d7341a
- Child:
- 4:2636fe1c6527
v1.3
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 | 3:a4994da37d1f | 8 | DigitalOut E_1(D8,0); //Control de electrovalvula 1 |
afsaavedram | 3:a4994da37d1f | 9 | DigitalOut E_2(D9,0); //Control de electrovalvula 2 |
afsaavedram | 3:a4994da37d1f | 10 | DigitalOut E_3(D10,0); //Control de electrovalvula 3 |
afsaavedram | 3:a4994da37d1f | 11 | DigitalOut E_4(D12,0); //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 | 3:a4994da37d1f | 24 | int temp_user_1=0; //tiempo tope de electrocoagulacion |
afsaavedram | 3:a4994da37d1f | 25 | int temp_user_2=0; //tiempo tope de reposo de la vinaza |
afsaavedram | 3:a4994da37d1f | 26 | int temp_user_3=0; //tiempo tope de vaciado del agua en el tanque 2 |
afsaavedram | 3:a4994da37d1f | 27 | int 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 | 3:a4994da37d1f | 51 | lcd.printf(" STOP!"); |
afsaavedram | 3:a4994da37d1f | 52 | lcd.locate(0,1); |
afsaavedram | 3:a4994da37d1f | 53 | lcd.printf(" PLEASE RESET"); |
afsaavedram | 3:a4994da37d1f | 54 | wait_ms(150); |
afsaavedram | 0:6cde030caebb | 55 | } |
afsaavedram | 0:6cde030caebb | 56 | } |
afsaavedram | 0:6cde030caebb | 57 | |
afsaavedram | 3:a4994da37d1f | 58 | void electro_1() |
afsaavedram | 0:6cde030caebb | 59 | { |
afsaavedram | 0:6cde030caebb | 60 | E_1=!E_1; |
afsaavedram | 0:6cde030caebb | 61 | } |
afsaavedram | 0:6cde030caebb | 62 | |
afsaavedram | 3:a4994da37d1f | 63 | void electro_2() |
afsaavedram | 0:6cde030caebb | 64 | { |
afsaavedram | 0:6cde030caebb | 65 | E_2=!E_2; |
afsaavedram | 0:6cde030caebb | 66 | } |
afsaavedram | 0:6cde030caebb | 67 | |
afsaavedram | 3:a4994da37d1f | 68 | void electro_3() |
afsaavedram | 0:6cde030caebb | 69 | { |
afsaavedram | 0:6cde030caebb | 70 | E_3=!E_3; |
afsaavedram | 0:6cde030caebb | 71 | } |
afsaavedram | 0:6cde030caebb | 72 | |
afsaavedram | 3:a4994da37d1f | 73 | void electro_4() |
afsaavedram | 0:6cde030caebb | 74 | { |
afsaavedram | 0:6cde030caebb | 75 | E_4=!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 | lcd.locate(0,0); |
afsaavedram | 0:6cde030caebb | 85 | lcd.printf(" Control para\n"); |
afsaavedram | 0:6cde030caebb | 86 | lcd.locate(0,1); |
afsaavedram | 0:6cde030caebb | 87 | lcd.printf("electrocoagular\n"); |
afsaavedram | 3:a4994da37d1f | 88 | wait(1.5); |
afsaavedram | 0:6cde030caebb | 89 | lcd.cls(); |
afsaavedram | 0:6cde030caebb | 90 | |
afsaavedram | 3:a4994da37d1f | 91 | |
afsaavedram | 2:4b27d3d7341a | 92 | |
afsaavedram | 2:4b27d3d7341a | 93 | |
afsaavedram | 0:6cde030caebb | 94 | while(1) { |
afsaavedram | 3:a4994da37d1f | 95 | ini_1: |
afsaavedram | 3:a4994da37d1f | 96 | lcd.cls(); |
afsaavedram | 3:a4994da37d1f | 97 | lcd.locate(0,0); |
afsaavedram | 3:a4994da37d1f | 98 | lcd.printf("t_1=%d",temp_user_1); |
afsaavedram | 3:a4994da37d1f | 99 | lcd.locate(8,0); |
afsaavedram | 3:a4994da37d1f | 100 | lcd.printf("t_2=%d",temp_user_2); |
afsaavedram | 3:a4994da37d1f | 101 | lcd.locate(0,1); |
afsaavedram | 3:a4994da37d1f | 102 | lcd.printf("t_3=%d",temp_user_3); |
afsaavedram | 3:a4994da37d1f | 103 | lcd.locate(8,1); |
afsaavedram | 3:a4994da37d1f | 104 | lcd.printf("t_4=%d",temp_user_4); |
afsaavedram | 3:a4994da37d1f | 105 | wait_ms(100); |
afsaavedram | 0:6cde030caebb | 106 | |
afsaavedram | 0:6cde030caebb | 107 | char key = keypad.getKey(); |
afsaavedram | 2:4b27d3d7341a | 108 | |
afsaavedram | 2:4b27d3d7341a | 109 | //if(key=='A') { |
afsaavedram | 3:a4994da37d1f | 110 | //lcd.cls(); |
afsaavedram | 3:a4994da37d1f | 111 | //lcd.locate(0,0); |
afsaavedram | 3:a4994da37d1f | 112 | //lcd.printf("%c",key); |
afsaavedram | 3:a4994da37d1f | 113 | //wait(3); |
afsaavedram | 2:4b27d3d7341a | 114 | |
afsaavedram | 3:a4994da37d1f | 115 | |
afsaavedram | 3:a4994da37d1f | 116 | |
afsaavedram | 3:a4994da37d1f | 117 | // lcd.printf("t_1=%f",temp_user_1); |
afsaavedram | 2:4b27d3d7341a | 118 | |
afsaavedram | 2:4b27d3d7341a | 119 | |
afsaavedram | 3:a4994da37d1f | 120 | if(key=='1') { |
afsaavedram | 3:a4994da37d1f | 121 | temp_user_1=temp_user_1+10; |
afsaavedram | 3:a4994da37d1f | 122 | if(temp_user_1<00) { |
afsaavedram | 3:a4994da37d1f | 123 | temp_user_1=00; |
afsaavedram | 3:a4994da37d1f | 124 | } |
afsaavedram | 3:a4994da37d1f | 125 | wait_ms(150); |
afsaavedram | 3:a4994da37d1f | 126 | } |
afsaavedram | 3:a4994da37d1f | 127 | if(key=='2') { |
afsaavedram | 3:a4994da37d1f | 128 | temp_user_1=temp_user_1-1; |
afsaavedram | 3:a4994da37d1f | 129 | if(temp_user_1<00) { |
afsaavedram | 3:a4994da37d1f | 130 | temp_user_1=00; |
afsaavedram | 3:a4994da37d1f | 131 | } |
afsaavedram | 3:a4994da37d1f | 132 | wait_ms(150); |
afsaavedram | 3:a4994da37d1f | 133 | } |
afsaavedram | 3:a4994da37d1f | 134 | if(key=='3') { |
afsaavedram | 3:a4994da37d1f | 135 | temp_user_2=temp_user_2+10; |
afsaavedram | 3:a4994da37d1f | 136 | if(temp_user_2<00) { |
afsaavedram | 3:a4994da37d1f | 137 | temp_user_2=00; |
afsaavedram | 3:a4994da37d1f | 138 | } |
afsaavedram | 3:a4994da37d1f | 139 | wait_ms(150); |
afsaavedram | 3:a4994da37d1f | 140 | } |
afsaavedram | 3:a4994da37d1f | 141 | if(key=='A') { |
afsaavedram | 3:a4994da37d1f | 142 | temp_user_2=temp_user_2-1; |
afsaavedram | 3:a4994da37d1f | 143 | if(temp_user_2<00) { |
afsaavedram | 3:a4994da37d1f | 144 | temp_user_2=00; |
afsaavedram | 3:a4994da37d1f | 145 | } |
afsaavedram | 3:a4994da37d1f | 146 | wait_ms(150); |
afsaavedram | 3:a4994da37d1f | 147 | } |
afsaavedram | 3:a4994da37d1f | 148 | if(key=='4') { |
afsaavedram | 3:a4994da37d1f | 149 | temp_user_3=temp_user_3+10; |
afsaavedram | 3:a4994da37d1f | 150 | if(temp_user_3<00) { |
afsaavedram | 3:a4994da37d1f | 151 | temp_user_3=00; |
afsaavedram | 3:a4994da37d1f | 152 | } |
afsaavedram | 3:a4994da37d1f | 153 | wait_ms(150); |
afsaavedram | 3:a4994da37d1f | 154 | } |
afsaavedram | 3:a4994da37d1f | 155 | if(key=='5') { |
afsaavedram | 3:a4994da37d1f | 156 | temp_user_3=temp_user_3-1; |
afsaavedram | 3:a4994da37d1f | 157 | if(temp_user_3<00) { |
afsaavedram | 3:a4994da37d1f | 158 | temp_user_3=00; |
afsaavedram | 3:a4994da37d1f | 159 | } |
afsaavedram | 3:a4994da37d1f | 160 | wait_ms(150); |
afsaavedram | 3:a4994da37d1f | 161 | } |
afsaavedram | 3:a4994da37d1f | 162 | if(key=='6') { |
afsaavedram | 3:a4994da37d1f | 163 | temp_user_4=temp_user_4+10; |
afsaavedram | 3:a4994da37d1f | 164 | if(temp_user_4<00) { |
afsaavedram | 3:a4994da37d1f | 165 | temp_user_4=00; |
afsaavedram | 3:a4994da37d1f | 166 | } |
afsaavedram | 3:a4994da37d1f | 167 | wait_ms(150); |
afsaavedram | 3:a4994da37d1f | 168 | } |
afsaavedram | 3:a4994da37d1f | 169 | if(key=='B') { |
afsaavedram | 3:a4994da37d1f | 170 | temp_user_4=temp_user_4-1; |
afsaavedram | 3:a4994da37d1f | 171 | if(temp_user_4<00) { |
afsaavedram | 3:a4994da37d1f | 172 | temp_user_4=00; |
afsaavedram | 3:a4994da37d1f | 173 | } |
afsaavedram | 3:a4994da37d1f | 174 | wait_ms(150); |
afsaavedram | 3:a4994da37d1f | 175 | } |
afsaavedram | 2:4b27d3d7341a | 176 | |
afsaavedram | 3:a4994da37d1f | 177 | /***********************COMIENZA CONTROL***********************/ |
afsaavedram | 3:a4994da37d1f | 178 | if(key=='D' && temp_user_1!=0) { |
afsaavedram | 3:a4994da37d1f | 179 | t_1.attach(&electro_1,temp_user_1); |
afsaavedram | 3:a4994da37d1f | 180 | |
afsaavedram | 3:a4994da37d1f | 181 | |
afsaavedram | 3:a4994da37d1f | 182 | |
afsaavedram | 3:a4994da37d1f | 183 | |
afsaavedram | 2:4b27d3d7341a | 184 | |
afsaavedram | 3:a4994da37d1f | 185 | } else if (key=='D' && temp_user_1==0) { |
afsaavedram | 3:a4994da37d1f | 186 | lcd.cls(); |
afsaavedram | 3:a4994da37d1f | 187 | lcd.printf(" t_1 empty"); |
afsaavedram | 3:a4994da37d1f | 188 | wait(1.5); |
afsaavedram | 3:a4994da37d1f | 189 | key='\0'; |
afsaavedram | 3:a4994da37d1f | 190 | goto ini_1; |
afsaavedram | 3:a4994da37d1f | 191 | } |
afsaavedram | 3:a4994da37d1f | 192 | |
afsaavedram | 3:a4994da37d1f | 193 | |
afsaavedram | 3:a4994da37d1f | 194 | /* |
afsaavedram | 3:a4994da37d1f | 195 | if(key=='A'){ |
afsaavedram | 3:a4994da37d1f | 196 | while(llena<=2){ |
afsaavedram | 3:a4994da37d1f | 197 | if(llena<3){ |
afsaavedram | 3:a4994da37d1f | 198 | cadena[llena]=keypad.getKey(); |
afsaavedram | 3:a4994da37d1f | 199 | temp_user_1=strtod(cadena,NULL); |
afsaavedram | 3:a4994da37d1f | 200 | llena++; |
afsaavedram | 3:a4994da37d1f | 201 | switch(llena){ |
afsaavedram | 3:a4994da37d1f | 202 | case 0: |
afsaavedram | 3:a4994da37d1f | 203 | if(llena==0 && keypad.getKey()!= '\0'){ |
afsaavedram | 3:a4994da37d1f | 204 | cadena[llena]=keypad.getKey(); |
afsaavedram | 3:a4994da37d1f | 205 | llena=llena +1; |
afsaavedram | 3:a4994da37d1f | 206 | break; |
afsaavedram | 2:4b27d3d7341a | 207 | } |
afsaavedram | 2:4b27d3d7341a | 208 | |
afsaavedram | 3:a4994da37d1f | 209 | case 1: |
afsaavedram | 3:a4994da37d1f | 210 | if(llena==1 && keypad.getKey()!= '\0'){ |
afsaavedram | 3:a4994da37d1f | 211 | cadena[llena]=keypad.getKey(); |
afsaavedram | 3:a4994da37d1f | 212 | llena=llena+1; |
afsaavedram | 3:a4994da37d1f | 213 | break; |
afsaavedram | 3:a4994da37d1f | 214 | } |
afsaavedram | 3:a4994da37d1f | 215 | |
afsaavedram | 3:a4994da37d1f | 216 | case 2: |
afsaavedram | 3:a4994da37d1f | 217 | if(llena==2 && keypad.getKey()!= '\0'){ |
afsaavedram | 3:a4994da37d1f | 218 | cadena[llena]=keypad.getKey(); |
afsaavedram | 3:a4994da37d1f | 219 | llena=llena+1; |
afsaavedram | 3:a4994da37d1f | 220 | break;} |
afsaavedram | 3:a4994da37d1f | 221 | |
afsaavedram | 3:a4994da37d1f | 222 | default: |
afsaavedram | 3:a4994da37d1f | 223 | break; |
afsaavedram | 3:a4994da37d1f | 224 | }*/ |
afsaavedram | 3:a4994da37d1f | 225 | //lcd.cls(); |
afsaavedram | 3:a4994da37d1f | 226 | //temp_user_1=strtod(cadena,NULL); |
afsaavedram | 3:a4994da37d1f | 227 | //lcd.locate(0,0); |
afsaavedram | 3:a4994da37d1f | 228 | //lcd.printf("t_1=%f",temp_user_1); |
afsaavedram | 3:a4994da37d1f | 229 | |
afsaavedram | 0:6cde030caebb | 230 | |
afsaavedram | 0:6cde030caebb | 231 | |
afsaavedram | 0:6cde030caebb | 232 | |
afsaavedram | 0:6cde030caebb | 233 | |
afsaavedram | 2:4b27d3d7341a | 234 | }//termina while de main |
afsaavedram | 2:4b27d3d7341a | 235 | }//termina main |