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: TSI TextLCD mbed
Fork of TP1_eje3_pruebas by
main.cpp@1:3f6a40496afa, 2018-05-03 (annotated)
- Committer:
- AntoPR
- Date:
- Thu May 03 15:23:42 2018 +0000
- Revision:
- 1:3f6a40496afa
- Parent:
- 0:ab9c6ff1dbc0
- Child:
- 2:cf60169c5172
se agrega el control del calentador con el sensor; falta apagar calentador con alarma
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AntoPR | 0:ab9c6ff1dbc0 | 1 | #include "mbed.h" |
AntoPR | 0:ab9c6ff1dbc0 | 2 | #include "TextLCD.h" |
AntoPR | 0:ab9c6ff1dbc0 | 3 | #include "TSISensor.h" |
AntoPR | 0:ab9c6ff1dbc0 | 4 | |
AntoPR | 0:ab9c6ff1dbc0 | 5 | TextLCD lcd(PTA1,PTA2,PTD4,PTA12,PTA4,PTA5,TextLCD::LCD16x2); |
AntoPR | 0:ab9c6ff1dbc0 | 6 | TSISensor tsi; |
AntoPR | 0:ab9c6ff1dbc0 | 7 | Ticker tim1; |
AntoPR | 0:ab9c6ff1dbc0 | 8 | Ticker tim2; |
AntoPR | 0:ab9c6ff1dbc0 | 9 | |
AntoPR | 0:ab9c6ff1dbc0 | 10 | /* Debug props |
AntoPR | 0:ab9c6ff1dbc0 | 11 | |
AntoPR | 0:ab9c6ff1dbc0 | 12 | */ |
AntoPR | 0:ab9c6ff1dbc0 | 13 | DigitalOut d_set_led(LED1); |
AntoPR | 0:ab9c6ff1dbc0 | 14 | |
AntoPR | 0:ab9c6ff1dbc0 | 15 | DigitalOut buzzer(PTC8); |
AntoPR | 0:ab9c6ff1dbc0 | 16 | DigitalOut alarma_led(PTC9); |
AntoPR | 0:ab9c6ff1dbc0 | 17 | |
AntoPR | 0:ab9c6ff1dbc0 | 18 | DigitalIn pull_setting(PTC3,PullUp);//sw_setting |
AntoPR | 0:ab9c6ff1dbc0 | 19 | DigitalIn pull_mode(PTC0,PullUp);//sw_mode |
AntoPR | 0:ab9c6ff1dbc0 | 20 | DigitalIn pull_enter(PTC7,PullUp);//sw_enter |
AntoPR | 0:ab9c6ff1dbc0 | 21 | |
AntoPR | 1:3f6a40496afa | 22 | AnalogIn sensor(PTB0); |
AntoPR | 1:3f6a40496afa | 23 | DigitalOut calefactor(PTC4); |
AntoPR | 0:ab9c6ff1dbc0 | 24 | |
AntoPR | 0:ab9c6ff1dbc0 | 25 | enum{TEMP, TIME}; //MODE_BUTTON_ME |
AntoPR | 0:ab9c6ff1dbc0 | 26 | enum{T_30MIN, T_1HORA, T_2HORAS}; //SET_OFF_TIME_ME |
AntoPR | 0:ab9c6ff1dbc0 | 27 | enum{PRENDIDO, APAGADO, APAGADO_2}; //ALARMA_ME |
AntoPR | 0:ab9c6ff1dbc0 | 28 | enum{SIN_PRESIONAR,ESPERA_TIMER,PRESIONADO,ESPERA_SOLTAR}; //ANTIREBOTE_ME |
AntoPR | 0:ab9c6ff1dbc0 | 29 | enum{NO_SETEANDO, SETEANDO}; //SETEANDO_ME |
AntoPR | 0:ab9c6ff1dbc0 | 30 | enum{WAIT,SETEADA};//SET_TEMP_SLIDER_ME |
AntoPR | 1:3f6a40496afa | 31 | enum{RES_ENCENDIDA,RES_APAGADA};//CONTROL_CALENTADOR_ME |
AntoPR | 0:ab9c6ff1dbc0 | 32 | |
AntoPR | 0:ab9c6ff1dbc0 | 33 | #define ALARMA_ON 1 //ALARMA_ME |
AntoPR | 0:ab9c6ff1dbc0 | 34 | #define ALARMA_OFF 0 |
AntoPR | 0:ab9c6ff1dbc0 | 35 | |
AntoPR | 0:ab9c6ff1dbc0 | 36 | #define LED_ON 1 //ALARMA_ME |
AntoPR | 0:ab9c6ff1dbc0 | 37 | #define LED_OFF 0 |
AntoPR | 0:ab9c6ff1dbc0 | 38 | |
AntoPR | 0:ab9c6ff1dbc0 | 39 | #define P_ON 0 //ANTIREBOTE_ME |
AntoPR | 0:ab9c6ff1dbc0 | 40 | #define P_OFF 1 |
AntoPR | 0:ab9c6ff1dbc0 | 41 | |
AntoPR | 1:3f6a40496afa | 42 | #define C_ON 1 //CONTROL_CALENTADOR_ME |
AntoPR | 1:3f6a40496afa | 43 | #define C_OFF 0 |
AntoPR | 1:3f6a40496afa | 44 | |
AntoPR | 0:ab9c6ff1dbc0 | 45 | #define TEMP_MAX 100 |
AntoPR | 0:ab9c6ff1dbc0 | 46 | #define SET_TEMPERATURA_INIT 25 |
AntoPR | 0:ab9c6ff1dbc0 | 47 | #define TEMP_SET 0 |
AntoPR | 1:3f6a40496afa | 48 | #define ERROR_RANGE 2 |
AntoPR | 0:ab9c6ff1dbc0 | 49 | #define TIME_OFF 1 |
AntoPR | 0:ab9c6ff1dbc0 | 50 | #define DEBUG_TIME 100 //100 = TRUE (debug), 1 = FALSE (normal operation) |
AntoPR | 0:ab9c6ff1dbc0 | 51 | #define MEDIA_HORA 1800/DEBUG_TIME |
AntoPR | 0:ab9c6ff1dbc0 | 52 | #define UNA_HORA 3600/DEBUG_TIME |
AntoPR | 0:ab9c6ff1dbc0 | 53 | #define DOS_HORAS 7200/DEBUG_TIME |
AntoPR | 0:ab9c6ff1dbc0 | 54 | #define SET_OFF_TIME_INIT DOS_HORAS //cambiar a gusto |
AntoPR | 0:ab9c6ff1dbc0 | 55 | #define UN_MINUTO 60/10 //10 for debug, 1 for normal operation |
AntoPR | 0:ab9c6ff1dbc0 | 56 | #define ANTIREBOTE_TMO 10 |
AntoPR | 0:ab9c6ff1dbc0 | 57 | |
AntoPR | 0:ab9c6ff1dbc0 | 58 | |
AntoPR | 0:ab9c6ff1dbc0 | 59 | void MODE_BUTTON_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 60 | unsigned char mode_estado = TEMP; |
AntoPR | 0:ab9c6ff1dbc0 | 61 | unsigned char mode = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 62 | unsigned int hor=0,minu=0,seg=0; |
AntoPR | 0:ab9c6ff1dbc0 | 63 | |
AntoPR | 0:ab9c6ff1dbc0 | 64 | void SET_OFF_TIME_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 65 | unsigned char set_off_time_estado = T_30MIN; |
AntoPR | 0:ab9c6ff1dbc0 | 66 | |
AntoPR | 0:ab9c6ff1dbc0 | 67 | void SET_TEMP_SLIDER_ME(void); |
AntoPR | 0:ab9c6ff1dbc0 | 68 | unsigned char set_temp_slider_estado=WAIT; |
AntoPR | 0:ab9c6ff1dbc0 | 69 | unsigned char t=0; |
AntoPR | 0:ab9c6ff1dbc0 | 70 | unsigned char set_temperatura=SET_TEMPERATURA_INIT; |
AntoPR | 0:ab9c6ff1dbc0 | 71 | |
AntoPR | 0:ab9c6ff1dbc0 | 72 | void CONTROL_CALENTADOR_ME(void); |
AntoPR | 0:ab9c6ff1dbc0 | 73 | unsigned char control_calentador_estado = RES_ENCENDIDA; |
AntoPR | 1:3f6a40496afa | 74 | float temp_real = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 75 | |
AntoPR | 0:ab9c6ff1dbc0 | 76 | void ALARMA_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 77 | unsigned char alarma_estado = APAGADO; |
AntoPR | 0:ab9c6ff1dbc0 | 78 | |
AntoPR | 0:ab9c6ff1dbc0 | 79 | void time_off(); |
AntoPR | 0:ab9c6ff1dbc0 | 80 | unsigned int set_off_time_tmo = SET_OFF_TIME_INIT; |
AntoPR | 0:ab9c6ff1dbc0 | 81 | unsigned int bz_tmo = SET_OFF_TIME_INIT - UN_MINUTO; |
AntoPR | 0:ab9c6ff1dbc0 | 82 | |
AntoPR | 0:ab9c6ff1dbc0 | 83 | void SETTING_ANTIREBOTE_ME (void); |
AntoPR | 0:ab9c6ff1dbc0 | 84 | unsigned char setting_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 85 | unsigned char sw_setting = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 86 | unsigned char seteando=0; |
AntoPR | 0:ab9c6ff1dbc0 | 87 | |
AntoPR | 0:ab9c6ff1dbc0 | 88 | void SETEANDO_ME(void); |
AntoPR | 0:ab9c6ff1dbc0 | 89 | unsigned char seteando_estado=NO_SETEANDO; |
AntoPR | 0:ab9c6ff1dbc0 | 90 | |
AntoPR | 0:ab9c6ff1dbc0 | 91 | void MODE_ANTIREBOTE_ME (void); |
AntoPR | 0:ab9c6ff1dbc0 | 92 | unsigned char mode_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 93 | unsigned char sw_mode = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 94 | |
AntoPR | 0:ab9c6ff1dbc0 | 95 | void ENTER_ANTIREBOTE_ME(void); |
AntoPR | 0:ab9c6ff1dbc0 | 96 | unsigned char enter_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 97 | unsigned char sw_enter = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 98 | |
AntoPR | 0:ab9c6ff1dbc0 | 99 | void t_10ms_antirebote(void); |
AntoPR | 0:ab9c6ff1dbc0 | 100 | unsigned char setting_antirebote_tmo=0; |
AntoPR | 0:ab9c6ff1dbc0 | 101 | unsigned char mode_antirebote_tmo=0; |
AntoPR | 0:ab9c6ff1dbc0 | 102 | unsigned char enter_antirebote_tmo=0; |
AntoPR | 0:ab9c6ff1dbc0 | 103 | |
AntoPR | 0:ab9c6ff1dbc0 | 104 | |
AntoPR | 0:ab9c6ff1dbc0 | 105 | int main() { |
AntoPR | 0:ab9c6ff1dbc0 | 106 | tim1.attach(&time_off,1); |
AntoPR | 0:ab9c6ff1dbc0 | 107 | tim2.attach(&t_10ms_antirebote,0.01); |
AntoPR | 1:3f6a40496afa | 108 | wait(1); |
AntoPR | 0:ab9c6ff1dbc0 | 109 | while(1) { |
AntoPR | 0:ab9c6ff1dbc0 | 110 | SETTING_ANTIREBOTE_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 111 | MODE_ANTIREBOTE_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 112 | ENTER_ANTIREBOTE_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 113 | SETEANDO_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 114 | wait(0.05); |
AntoPR | 0:ab9c6ff1dbc0 | 115 | MODE_BUTTON_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 116 | wait(0.05); |
AntoPR | 0:ab9c6ff1dbc0 | 117 | SET_TEMP_SLIDER_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 118 | wait(0.05); |
AntoPR | 0:ab9c6ff1dbc0 | 119 | SET_OFF_TIME_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 120 | wait(0.05); |
AntoPR | 1:3f6a40496afa | 121 | CONTROL_CALENTADOR_ME(); |
AntoPR | 1:3f6a40496afa | 122 | wait(0.01); |
AntoPR | 0:ab9c6ff1dbc0 | 123 | ALARMA_ME(); |
AntoPR | 0:ab9c6ff1dbc0 | 124 | } |
AntoPR | 0:ab9c6ff1dbc0 | 125 | } |
AntoPR | 0:ab9c6ff1dbc0 | 126 | |
AntoPR | 0:ab9c6ff1dbc0 | 127 | void time_off(){ |
AntoPR | 0:ab9c6ff1dbc0 | 128 | if (set_off_time_tmo>0) |
AntoPR | 0:ab9c6ff1dbc0 | 129 | set_off_time_tmo--; |
AntoPR | 0:ab9c6ff1dbc0 | 130 | |
AntoPR | 0:ab9c6ff1dbc0 | 131 | if(bz_tmo>0) |
AntoPR | 0:ab9c6ff1dbc0 | 132 | bz_tmo--; |
AntoPR | 0:ab9c6ff1dbc0 | 133 | } |
AntoPR | 0:ab9c6ff1dbc0 | 134 | |
AntoPR | 0:ab9c6ff1dbc0 | 135 | void t_10ms_antirebote (){ |
AntoPR | 0:ab9c6ff1dbc0 | 136 | if(setting_antirebote_tmo > 0) |
AntoPR | 0:ab9c6ff1dbc0 | 137 | setting_antirebote_tmo--; |
AntoPR | 0:ab9c6ff1dbc0 | 138 | |
AntoPR | 0:ab9c6ff1dbc0 | 139 | if(mode_antirebote_tmo > 0) |
AntoPR | 0:ab9c6ff1dbc0 | 140 | mode_antirebote_tmo--; |
AntoPR | 0:ab9c6ff1dbc0 | 141 | |
AntoPR | 0:ab9c6ff1dbc0 | 142 | if(enter_antirebote_tmo > 0) |
AntoPR | 0:ab9c6ff1dbc0 | 143 | enter_antirebote_tmo--; |
AntoPR | 0:ab9c6ff1dbc0 | 144 | } |
AntoPR | 0:ab9c6ff1dbc0 | 145 | |
AntoPR | 0:ab9c6ff1dbc0 | 146 | void SETEANDO_ME(){ |
AntoPR | 0:ab9c6ff1dbc0 | 147 | switch(seteando_estado){ |
AntoPR | 0:ab9c6ff1dbc0 | 148 | default: |
AntoPR | 0:ab9c6ff1dbc0 | 149 | case NO_SETEANDO: |
AntoPR | 0:ab9c6ff1dbc0 | 150 | seteando=0; |
AntoPR | 0:ab9c6ff1dbc0 | 151 | d_set_led=1;// debug led off |
AntoPR | 1:3f6a40496afa | 152 | lcd.locate(14,0); |
AntoPR | 0:ab9c6ff1dbc0 | 153 | lcd.printf("NS"); |
AntoPR | 0:ab9c6ff1dbc0 | 154 | if(sw_setting==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 155 | seteando_estado=SETEANDO; |
AntoPR | 0:ab9c6ff1dbc0 | 156 | /* RESET DE SET_TEMP_SLIDER_ME y ALARMA_ME |
AntoPR | 0:ab9c6ff1dbc0 | 157 | */ |
AntoPR | 0:ab9c6ff1dbc0 | 158 | set_temp_slider_estado=WAIT; |
AntoPR | 0:ab9c6ff1dbc0 | 159 | } |
AntoPR | 0:ab9c6ff1dbc0 | 160 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 161 | case SETEANDO: |
AntoPR | 0:ab9c6ff1dbc0 | 162 | seteando=1; |
AntoPR | 0:ab9c6ff1dbc0 | 163 | d_set_led=0;//debug led on |
AntoPR | 1:3f6a40496afa | 164 | lcd.locate(14,0); |
AntoPR | 0:ab9c6ff1dbc0 | 165 | lcd.printf(" S"); |
AntoPR | 0:ab9c6ff1dbc0 | 166 | if(sw_setting==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 167 | seteando_estado=NO_SETEANDO; |
AntoPR | 0:ab9c6ff1dbc0 | 168 | } |
AntoPR | 0:ab9c6ff1dbc0 | 169 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 170 | }//cierra sw |
AntoPR | 0:ab9c6ff1dbc0 | 171 | }//cierra SETEANDO_ME |
AntoPR | 0:ab9c6ff1dbc0 | 172 | |
AntoPR | 0:ab9c6ff1dbc0 | 173 | void MODE_BUTTON_ME(){ |
AntoPR | 0:ab9c6ff1dbc0 | 174 | switch (mode_estado){ |
AntoPR | 0:ab9c6ff1dbc0 | 175 | default: |
AntoPR | 0:ab9c6ff1dbc0 | 176 | case TEMP: |
AntoPR | 0:ab9c6ff1dbc0 | 177 | mode=TEMP_SET; |
AntoPR | 0:ab9c6ff1dbc0 | 178 | //lcd.cls(); |
AntoPR | 0:ab9c6ff1dbc0 | 179 | lcd.locate(0,0); |
AntoPR | 1:3f6a40496afa | 180 | lcd.printf("TEMP SET: "); |
AntoPR | 1:3f6a40496afa | 181 | lcd.locate(10,0); |
AntoPR | 0:ab9c6ff1dbc0 | 182 | if(seteando==0){ |
AntoPR | 1:3f6a40496afa | 183 | lcd.printf("%d ",set_temperatura); |
AntoPR | 0:ab9c6ff1dbc0 | 184 | } |
AntoPR | 0:ab9c6ff1dbc0 | 185 | if (sw_mode==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 186 | mode_estado=TIME; |
AntoPR | 0:ab9c6ff1dbc0 | 187 | } |
AntoPR | 0:ab9c6ff1dbc0 | 188 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 189 | case TIME: |
AntoPR | 0:ab9c6ff1dbc0 | 190 | mode=TIME_OFF; |
AntoPR | 0:ab9c6ff1dbc0 | 191 | //lcd.cls(); |
AntoPR | 0:ab9c6ff1dbc0 | 192 | lcd.locate(0,0); |
AntoPR | 1:3f6a40496afa | 193 | lcd.printf("TIEMPO OFF: "); |
AntoPR | 0:ab9c6ff1dbc0 | 194 | lcd.locate(0,1); |
AntoPR | 0:ab9c6ff1dbc0 | 195 | if(seteando==0){ |
AntoPR | 0:ab9c6ff1dbc0 | 196 | hor = (int)(set_off_time_tmo / 3600); |
AntoPR | 0:ab9c6ff1dbc0 | 197 | minu = (int)((set_off_time_tmo - hor * 3600) / 60); |
AntoPR | 0:ab9c6ff1dbc0 | 198 | seg = set_off_time_tmo - (hor * 3600 + minu * 60); |
AntoPR | 1:3f6a40496afa | 199 | lcd.printf("%02d:%02d:%02d ",hor,minu,seg); |
AntoPR | 0:ab9c6ff1dbc0 | 200 | } |
AntoPR | 0:ab9c6ff1dbc0 | 201 | if (sw_mode==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 202 | mode_estado=TEMP; |
AntoPR | 0:ab9c6ff1dbc0 | 203 | } |
AntoPR | 0:ab9c6ff1dbc0 | 204 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 205 | }//cierra sw |
AntoPR | 0:ab9c6ff1dbc0 | 206 | }//cierra MODE_BUTTON_ME |
AntoPR | 0:ab9c6ff1dbc0 | 207 | |
AntoPR | 0:ab9c6ff1dbc0 | 208 | void SET_OFF_TIME_ME(){ |
AntoPR | 0:ab9c6ff1dbc0 | 209 | if(seteando==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 210 | if(mode==TIME_OFF){ |
AntoPR | 0:ab9c6ff1dbc0 | 211 | switch (set_off_time_estado){ |
AntoPR | 0:ab9c6ff1dbc0 | 212 | default: |
AntoPR | 0:ab9c6ff1dbc0 | 213 | case T_30MIN: |
AntoPR | 0:ab9c6ff1dbc0 | 214 | set_off_time_tmo=MEDIA_HORA; //EN SEG |
AntoPR | 1:3f6a40496afa | 215 | lcd.printf("30 minutos "); |
AntoPR | 0:ab9c6ff1dbc0 | 216 | if(sw_enter==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 217 | set_off_time_estado=T_1HORA; |
AntoPR | 0:ab9c6ff1dbc0 | 218 | } |
AntoPR | 0:ab9c6ff1dbc0 | 219 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 220 | case T_1HORA: |
AntoPR | 0:ab9c6ff1dbc0 | 221 | set_off_time_tmo=UNA_HORA; //EN SEG |
AntoPR | 1:3f6a40496afa | 222 | lcd.printf("1 hora "); |
AntoPR | 0:ab9c6ff1dbc0 | 223 | if(sw_enter==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 224 | set_off_time_estado=T_2HORAS; |
AntoPR | 0:ab9c6ff1dbc0 | 225 | } |
AntoPR | 0:ab9c6ff1dbc0 | 226 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 227 | case T_2HORAS: |
AntoPR | 0:ab9c6ff1dbc0 | 228 | set_off_time_tmo=DOS_HORAS; //EN SEG |
AntoPR | 1:3f6a40496afa | 229 | lcd.printf("2 horas "); |
AntoPR | 0:ab9c6ff1dbc0 | 230 | if(sw_enter==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 231 | set_off_time_estado=T_30MIN; |
AntoPR | 0:ab9c6ff1dbc0 | 232 | } |
AntoPR | 0:ab9c6ff1dbc0 | 233 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 234 | }//cierra sw |
AntoPR | 0:ab9c6ff1dbc0 | 235 | bz_tmo = set_off_time_tmo - UN_MINUTO; //la alarma debe sonar 1 minuto antes de apagarse |
AntoPR | 0:ab9c6ff1dbc0 | 236 | wait(0.1); |
AntoPR | 0:ab9c6ff1dbc0 | 237 | }//cierra if mode |
AntoPR | 0:ab9c6ff1dbc0 | 238 | }//cierra if seteando |
AntoPR | 0:ab9c6ff1dbc0 | 239 | }//cierra SET_OFF_TIME_ME |
AntoPR | 0:ab9c6ff1dbc0 | 240 | |
AntoPR | 0:ab9c6ff1dbc0 | 241 | void SET_TEMP_SLIDER_ME(){ |
AntoPR | 0:ab9c6ff1dbc0 | 242 | if(seteando==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 243 | if(mode==TEMP_SET){ |
AntoPR | 0:ab9c6ff1dbc0 | 244 | switch(set_temp_slider_estado){ |
AntoPR | 0:ab9c6ff1dbc0 | 245 | default: |
AntoPR | 0:ab9c6ff1dbc0 | 246 | case WAIT: |
AntoPR | 0:ab9c6ff1dbc0 | 247 | t = (tsi.readDistance() * TEMP_MAX) / 40; |
AntoPR | 1:3f6a40496afa | 248 | lcd.printf("%d ",t); |
AntoPR | 0:ab9c6ff1dbc0 | 249 | if(sw_enter == 1){ |
AntoPR | 0:ab9c6ff1dbc0 | 250 | set_temperatura = t; |
AntoPR | 0:ab9c6ff1dbc0 | 251 | set_temp_slider_estado=SETEADA; |
AntoPR | 0:ab9c6ff1dbc0 | 252 | } |
AntoPR | 0:ab9c6ff1dbc0 | 253 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 254 | case SETEADA: |
AntoPR | 1:3f6a40496afa | 255 | lcd.printf("%d ",set_temperatura); |
AntoPR | 0:ab9c6ff1dbc0 | 256 | /*if(sw_setting == 1) |
AntoPR | 0:ab9c6ff1dbc0 | 257 | set_temp_slider_estado=WAIT;*/ |
AntoPR | 0:ab9c6ff1dbc0 | 258 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 259 | }//cierra sw |
AntoPR | 0:ab9c6ff1dbc0 | 260 | }//cierra if mode |
AntoPR | 0:ab9c6ff1dbc0 | 261 | }//cierra if seteando |
AntoPR | 0:ab9c6ff1dbc0 | 262 | }//cierra SET_TEMP_SLIDER_ME |
AntoPR | 0:ab9c6ff1dbc0 | 263 | |
AntoPR | 1:3f6a40496afa | 264 | void CONTROL_CALENTADOR_ME(){ |
AntoPR | 1:3f6a40496afa | 265 | switch(control_calentador_estado){ |
AntoPR | 1:3f6a40496afa | 266 | default: |
AntoPR | 1:3f6a40496afa | 267 | case RES_ENCENDIDA: |
AntoPR | 1:3f6a40496afa | 268 | calefactor= C_ON; |
AntoPR | 1:3f6a40496afa | 269 | temp_real = sensor.read()*TEMP_MAX; |
AntoPR | 1:3f6a40496afa | 270 | if(mode==TEMP){ |
AntoPR | 1:3f6a40496afa | 271 | lcd.locate(0,1); |
AntoPR | 1:3f6a40496afa | 272 | lcd.printf("TEMP REAL: %02.2f",temp_real); |
AntoPR | 1:3f6a40496afa | 273 | } |
AntoPR | 1:3f6a40496afa | 274 | if(temp_real > (set_temperatura + ERROR_RANGE)){ |
AntoPR | 1:3f6a40496afa | 275 | control_calentador_estado = RES_APAGADA; |
AntoPR | 1:3f6a40496afa | 276 | } |
AntoPR | 1:3f6a40496afa | 277 | break; |
AntoPR | 1:3f6a40496afa | 278 | case RES_APAGADA: |
AntoPR | 1:3f6a40496afa | 279 | calefactor=C_OFF; |
AntoPR | 1:3f6a40496afa | 280 | temp_real = sensor.read()*TEMP_MAX; |
AntoPR | 1:3f6a40496afa | 281 | if(mode==TEMP){ |
AntoPR | 1:3f6a40496afa | 282 | lcd.locate(0,1); |
AntoPR | 1:3f6a40496afa | 283 | lcd.printf("TEMP REAL: %02.2f",temp_real); |
AntoPR | 1:3f6a40496afa | 284 | } |
AntoPR | 1:3f6a40496afa | 285 | if(temp_real < (set_temperatura - ERROR_RANGE)){ |
AntoPR | 1:3f6a40496afa | 286 | control_calentador_estado = RES_ENCENDIDA; |
AntoPR | 1:3f6a40496afa | 287 | } |
AntoPR | 1:3f6a40496afa | 288 | break; |
AntoPR | 1:3f6a40496afa | 289 | }//cierra sw |
AntoPR | 1:3f6a40496afa | 290 | }//cierra CONTROL_CALENTADOR_ME |
AntoPR | 1:3f6a40496afa | 291 | |
AntoPR | 0:ab9c6ff1dbc0 | 292 | void ALARMA_ME(){ |
AntoPR | 0:ab9c6ff1dbc0 | 293 | switch(alarma_estado){ |
AntoPR | 0:ab9c6ff1dbc0 | 294 | default: |
AntoPR | 0:ab9c6ff1dbc0 | 295 | case APAGADO: |
AntoPR | 0:ab9c6ff1dbc0 | 296 | buzzer=0;//off |
AntoPR | 0:ab9c6ff1dbc0 | 297 | alarma_led=LED_OFF; |
AntoPR | 0:ab9c6ff1dbc0 | 298 | if(bz_tmo==0){ |
AntoPR | 0:ab9c6ff1dbc0 | 299 | alarma_estado=PRENDIDO; |
AntoPR | 0:ab9c6ff1dbc0 | 300 | bz_tmo=2;//2 segundos on |
AntoPR | 0:ab9c6ff1dbc0 | 301 | } |
AntoPR | 0:ab9c6ff1dbc0 | 302 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 303 | case PRENDIDO: |
AntoPR | 0:ab9c6ff1dbc0 | 304 | buzzer=1;//on |
AntoPR | 0:ab9c6ff1dbc0 | 305 | alarma_led = LED_ON; |
AntoPR | 0:ab9c6ff1dbc0 | 306 | if(bz_tmo==0){ |
AntoPR | 0:ab9c6ff1dbc0 | 307 | alarma_estado=APAGADO_2; |
AntoPR | 0:ab9c6ff1dbc0 | 308 | } |
AntoPR | 0:ab9c6ff1dbc0 | 309 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 310 | case APAGADO_2: |
AntoPR | 0:ab9c6ff1dbc0 | 311 | buzzer=0;//off |
AntoPR | 0:ab9c6ff1dbc0 | 312 | alarma_led=LED_ON; |
AntoPR | 0:ab9c6ff1dbc0 | 313 | if(sw_setting==1){ |
AntoPR | 0:ab9c6ff1dbc0 | 314 | set_off_time_tmo = SET_OFF_TIME_INIT; |
AntoPR | 0:ab9c6ff1dbc0 | 315 | bz_tmo = SET_OFF_TIME_INIT - UN_MINUTO; |
AntoPR | 0:ab9c6ff1dbc0 | 316 | alarma_estado=APAGADO; |
AntoPR | 0:ab9c6ff1dbc0 | 317 | } |
AntoPR | 0:ab9c6ff1dbc0 | 318 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 319 | }//cierra sw |
AntoPR | 0:ab9c6ff1dbc0 | 320 | }//cierra ME |
AntoPR | 0:ab9c6ff1dbc0 | 321 | |
AntoPR | 0:ab9c6ff1dbc0 | 322 | |
AntoPR | 0:ab9c6ff1dbc0 | 323 | void SETTING_ANTIREBOTE_ME(){ |
AntoPR | 0:ab9c6ff1dbc0 | 324 | switch(setting_antirebote_estado){ |
AntoPR | 0:ab9c6ff1dbc0 | 325 | default: |
AntoPR | 0:ab9c6ff1dbc0 | 326 | case SIN_PRESIONAR: |
AntoPR | 0:ab9c6ff1dbc0 | 327 | sw_setting = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 328 | if(pull_setting==P_ON){ |
AntoPR | 0:ab9c6ff1dbc0 | 329 | setting_antirebote_estado = ESPERA_TIMER; |
AntoPR | 0:ab9c6ff1dbc0 | 330 | setting_antirebote_tmo = ANTIREBOTE_TMO; |
AntoPR | 0:ab9c6ff1dbc0 | 331 | } |
AntoPR | 0:ab9c6ff1dbc0 | 332 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 333 | case ESPERA_TIMER: |
AntoPR | 0:ab9c6ff1dbc0 | 334 | sw_setting = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 335 | if(setting_antirebote_tmo == 0){ |
AntoPR | 0:ab9c6ff1dbc0 | 336 | if(pull_setting==P_ON) |
AntoPR | 0:ab9c6ff1dbc0 | 337 | setting_antirebote_estado = PRESIONADO; |
AntoPR | 0:ab9c6ff1dbc0 | 338 | else |
AntoPR | 0:ab9c6ff1dbc0 | 339 | setting_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 340 | } |
AntoPR | 0:ab9c6ff1dbc0 | 341 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 342 | case PRESIONADO: |
AntoPR | 0:ab9c6ff1dbc0 | 343 | sw_setting = 1; |
AntoPR | 0:ab9c6ff1dbc0 | 344 | setting_antirebote_estado = ESPERA_SOLTAR; |
AntoPR | 0:ab9c6ff1dbc0 | 345 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 346 | case ESPERA_SOLTAR: |
AntoPR | 0:ab9c6ff1dbc0 | 347 | sw_setting = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 348 | if(pull_setting == P_OFF) |
AntoPR | 0:ab9c6ff1dbc0 | 349 | setting_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 350 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 351 | }//ciera sw |
AntoPR | 0:ab9c6ff1dbc0 | 352 | }//cierra ANTIREBOTE_ME |
AntoPR | 0:ab9c6ff1dbc0 | 353 | |
AntoPR | 0:ab9c6ff1dbc0 | 354 | void MODE_ANTIREBOTE_ME(){ |
AntoPR | 0:ab9c6ff1dbc0 | 355 | switch(mode_antirebote_estado){ |
AntoPR | 0:ab9c6ff1dbc0 | 356 | default: |
AntoPR | 0:ab9c6ff1dbc0 | 357 | case SIN_PRESIONAR: |
AntoPR | 0:ab9c6ff1dbc0 | 358 | sw_mode = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 359 | if(pull_mode==P_ON){ |
AntoPR | 0:ab9c6ff1dbc0 | 360 | mode_antirebote_estado = ESPERA_TIMER; |
AntoPR | 0:ab9c6ff1dbc0 | 361 | mode_antirebote_tmo = ANTIREBOTE_TMO; |
AntoPR | 0:ab9c6ff1dbc0 | 362 | } |
AntoPR | 0:ab9c6ff1dbc0 | 363 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 364 | case ESPERA_TIMER: |
AntoPR | 0:ab9c6ff1dbc0 | 365 | sw_mode = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 366 | if(mode_antirebote_tmo == 0){ |
AntoPR | 0:ab9c6ff1dbc0 | 367 | if(pull_mode==P_ON) |
AntoPR | 0:ab9c6ff1dbc0 | 368 | mode_antirebote_estado = PRESIONADO; |
AntoPR | 0:ab9c6ff1dbc0 | 369 | else |
AntoPR | 0:ab9c6ff1dbc0 | 370 | mode_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 371 | } |
AntoPR | 0:ab9c6ff1dbc0 | 372 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 373 | case PRESIONADO: |
AntoPR | 0:ab9c6ff1dbc0 | 374 | sw_mode = 1; |
AntoPR | 0:ab9c6ff1dbc0 | 375 | mode_antirebote_estado = ESPERA_SOLTAR; |
AntoPR | 0:ab9c6ff1dbc0 | 376 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 377 | case ESPERA_SOLTAR: |
AntoPR | 0:ab9c6ff1dbc0 | 378 | sw_mode = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 379 | if(pull_mode == P_OFF) |
AntoPR | 0:ab9c6ff1dbc0 | 380 | mode_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 381 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 382 | }//ciera sw |
AntoPR | 0:ab9c6ff1dbc0 | 383 | }//cierra ANTIREBOTE_ME |
AntoPR | 0:ab9c6ff1dbc0 | 384 | |
AntoPR | 0:ab9c6ff1dbc0 | 385 | void ENTER_ANTIREBOTE_ME(){ |
AntoPR | 0:ab9c6ff1dbc0 | 386 | switch(enter_antirebote_estado){ |
AntoPR | 0:ab9c6ff1dbc0 | 387 | default: |
AntoPR | 0:ab9c6ff1dbc0 | 388 | case SIN_PRESIONAR: |
AntoPR | 0:ab9c6ff1dbc0 | 389 | sw_enter = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 390 | if(pull_enter==P_ON){ |
AntoPR | 0:ab9c6ff1dbc0 | 391 | enter_antirebote_estado = ESPERA_TIMER; |
AntoPR | 0:ab9c6ff1dbc0 | 392 | enter_antirebote_tmo = ANTIREBOTE_TMO; |
AntoPR | 0:ab9c6ff1dbc0 | 393 | } |
AntoPR | 0:ab9c6ff1dbc0 | 394 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 395 | case ESPERA_TIMER: |
AntoPR | 0:ab9c6ff1dbc0 | 396 | sw_enter = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 397 | if(enter_antirebote_tmo == 0){ |
AntoPR | 0:ab9c6ff1dbc0 | 398 | if(pull_enter==P_ON) |
AntoPR | 0:ab9c6ff1dbc0 | 399 | enter_antirebote_estado = PRESIONADO; |
AntoPR | 0:ab9c6ff1dbc0 | 400 | else |
AntoPR | 0:ab9c6ff1dbc0 | 401 | enter_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 402 | } |
AntoPR | 0:ab9c6ff1dbc0 | 403 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 404 | case PRESIONADO: |
AntoPR | 0:ab9c6ff1dbc0 | 405 | sw_enter = 1; |
AntoPR | 0:ab9c6ff1dbc0 | 406 | enter_antirebote_estado = ESPERA_SOLTAR; |
AntoPR | 0:ab9c6ff1dbc0 | 407 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 408 | case ESPERA_SOLTAR: |
AntoPR | 0:ab9c6ff1dbc0 | 409 | sw_enter = 0; |
AntoPR | 0:ab9c6ff1dbc0 | 410 | if(pull_enter == P_OFF) |
AntoPR | 0:ab9c6ff1dbc0 | 411 | enter_antirebote_estado = SIN_PRESIONAR; |
AntoPR | 0:ab9c6ff1dbc0 | 412 | break; |
AntoPR | 0:ab9c6ff1dbc0 | 413 | }//ciera sw |
AntoPR | 0:ab9c6ff1dbc0 | 414 | }//cierra ANTIREBOTE_ME |