electro
Dependencies: mbed QEI mbed-os KeypadLib TextLCD
electrocoagulador_final.cpp@2:4b27d3d7341a, 2019-03-02 (annotated)
- Committer:
- afsaavedram
- Date:
- Sat Mar 02 02:07:39 2019 +0000
- Revision:
- 2:4b27d3d7341a
- Parent:
- 1:48c8726d6824
- Child:
- 3:a4994da37d1f
v1.2
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 | 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 | 0:6cde030caebb | 88 | wait(3); |
afsaavedram | 0:6cde030caebb | 89 | lcd.cls(); |
afsaavedram | 0:6cde030caebb | 90 | |
afsaavedram | 2:4b27d3d7341a | 91 | lcd.locate(0,0); |
afsaavedram | 2:4b27d3d7341a | 92 | lcd.printf("t_1=%f",temp_user_1); |
afsaavedram | 2:4b27d3d7341a | 93 | lcd.locate(8,0); |
afsaavedram | 2:4b27d3d7341a | 94 | lcd.printf("t_2=%f",temp_user_2); |
afsaavedram | 2:4b27d3d7341a | 95 | lcd.locate(0,1); |
afsaavedram | 2:4b27d3d7341a | 96 | lcd.printf("t_3=%f",temp_user_3); |
afsaavedram | 2:4b27d3d7341a | 97 | lcd.locate(8,1); |
afsaavedram | 2:4b27d3d7341a | 98 | lcd.printf("t_4=%f",temp_user_4); |
afsaavedram | 2:4b27d3d7341a | 99 | |
afsaavedram | 2:4b27d3d7341a | 100 | |
afsaavedram | 0:6cde030caebb | 101 | while(1) { |
afsaavedram | 0:6cde030caebb | 102 | |
afsaavedram | 0:6cde030caebb | 103 | char key = keypad.getKey(); |
afsaavedram | 2:4b27d3d7341a | 104 | |
afsaavedram | 2:4b27d3d7341a | 105 | //if(key=='A') { |
afsaavedram | 2:4b27d3d7341a | 106 | //lcd.cls(); |
afsaavedram | 2:4b27d3d7341a | 107 | //lcd.locate(0,0); |
afsaavedram | 2:4b27d3d7341a | 108 | //lcd.printf("%c",key); |
afsaavedram | 2:4b27d3d7341a | 109 | //wait(3); |
afsaavedram | 2:4b27d3d7341a | 110 | |
afsaavedram | 2:4b27d3d7341a | 111 | |
afsaavedram | 2:4b27d3d7341a | 112 | |
afsaavedram | 2:4b27d3d7341a | 113 | // lcd.printf("t_1=%f",temp_user_1); |
afsaavedram | 2:4b27d3d7341a | 114 | |
afsaavedram | 2:4b27d3d7341a | 115 | |
afsaavedram | 2:4b27d3d7341a | 116 | //if(key=='A'){temp_user_1=10;} |
afsaavedram | 2:4b27d3d7341a | 117 | |
afsaavedram | 2:4b27d3d7341a | 118 | if(key=='A'){ |
afsaavedram | 2:4b27d3d7341a | 119 | while(llena<=2){ |
afsaavedram | 2:4b27d3d7341a | 120 | switch(llena){ |
afsaavedram | 2:4b27d3d7341a | 121 | case 0: |
afsaavedram | 2:4b27d3d7341a | 122 | if(llena==0 && keypad.getKey()!= '\0'){ |
afsaavedram | 2:4b27d3d7341a | 123 | cadena[llena]=keypad.getKey(); |
afsaavedram | 2:4b27d3d7341a | 124 | llena=llena +1; |
afsaavedram | 2:4b27d3d7341a | 125 | break; |
afsaavedram | 2:4b27d3d7341a | 126 | } |
afsaavedram | 2:4b27d3d7341a | 127 | |
afsaavedram | 2:4b27d3d7341a | 128 | case 1: |
afsaavedram | 2:4b27d3d7341a | 129 | if(llena==1 && keypad.getKey()!= '\0'){ |
afsaavedram | 2:4b27d3d7341a | 130 | cadena[llena]=keypad.getKey(); |
afsaavedram | 2:4b27d3d7341a | 131 | llena=llena+1; |
afsaavedram | 2:4b27d3d7341a | 132 | break; |
afsaavedram | 2:4b27d3d7341a | 133 | } |
afsaavedram | 2:4b27d3d7341a | 134 | |
afsaavedram | 2:4b27d3d7341a | 135 | case 2: |
afsaavedram | 2:4b27d3d7341a | 136 | if(llena==2 && keypad.getKey()!= '\0'){ |
afsaavedram | 2:4b27d3d7341a | 137 | cadena[llena]=keypad.getKey(); |
afsaavedram | 2:4b27d3d7341a | 138 | llena=llena+1; |
afsaavedram | 2:4b27d3d7341a | 139 | break;} |
afsaavedram | 2:4b27d3d7341a | 140 | |
afsaavedram | 2:4b27d3d7341a | 141 | default: |
afsaavedram | 2:4b27d3d7341a | 142 | break; |
afsaavedram | 2:4b27d3d7341a | 143 | } |
afsaavedram | 2:4b27d3d7341a | 144 | lcd.cls(); |
afsaavedram | 2:4b27d3d7341a | 145 | temp_user_1=strtod(cadena,NULL); |
afsaavedram | 2:4b27d3d7341a | 146 | lcd.locate(0,0); |
afsaavedram | 2:4b27d3d7341a | 147 | lcd.printf("t_1=%f",temp_user_1); |
afsaavedram | 2:4b27d3d7341a | 148 | } |
afsaavedram | 2:4b27d3d7341a | 149 | |
afsaavedram | 2:4b27d3d7341a | 150 | } |
afsaavedram | 0:6cde030caebb | 151 | |
afsaavedram | 0:6cde030caebb | 152 | |
afsaavedram | 0:6cde030caebb | 153 | |
afsaavedram | 0:6cde030caebb | 154 | |
afsaavedram | 2:4b27d3d7341a | 155 | }//termina while de main |
afsaavedram | 2:4b27d3d7341a | 156 | }//termina main |