Control Remoto para subir, detener o bajar una cortina y con la posibilidad de programar otras teclas / cada función enciende un color de led diferente / cada tecla prende o apaga la función / En el LCD se muestra la tecla presionada, y los valores de alto, bajo, distancia del bit, cero y uno logico
Dependencies: DebouncedIn Pulse1 TextLCD mbed
ProgramaControl.cpp@0:a2790441065a, 2014-05-23 (annotated)
- Committer:
- jaruiz
- Date:
- Fri May 23 20:01:49 2014 +0000
- Revision:
- 0:a2790441065a
Tarea6_ControlRemoto_RuizJose_PelaezSebastian
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jaruiz | 0:a2790441065a | 1 | #include "mbed.h" |
jaruiz | 0:a2790441065a | 2 | #include <Pulse1.h> |
jaruiz | 0:a2790441065a | 3 | #include "TextLCD.h" |
jaruiz | 0:a2790441065a | 4 | #include "DebouncedIn.h" |
jaruiz | 0:a2790441065a | 5 | |
jaruiz | 0:a2790441065a | 6 | |
jaruiz | 0:a2790441065a | 7 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); |
jaruiz | 0:a2790441065a | 8 | PulseInOut irda(PTD5); |
jaruiz | 0:a2790441065a | 9 | DigitalOut led(LED1); // LED ROJO |
jaruiz | 0:a2790441065a | 10 | DigitalOut led2(LED2);// LED VERDE |
jaruiz | 0:a2790441065a | 11 | DigitalOut led3(LED3); // LED AZUL |
jaruiz | 0:a2790441065a | 12 | AnalogOut Vout(PTE30); // SALIDA SONIDO |
jaruiz | 0:a2790441065a | 13 | |
jaruiz | 0:a2790441065a | 14 | int header =0; // Tiempo Cabecera |
jaruiz | 0:a2790441065a | 15 | const int head_H = 9120; //+10% OSCILOSCOPIO |
jaruiz | 0:a2790441065a | 16 | const int head_L = 8939;//-10% OSCILOSCOPIO |
jaruiz | 0:a2790441065a | 17 | const int Tp=300; |
jaruiz | 0:a2790441065a | 18 | int i=0; |
jaruiz | 0:a2790441065a | 19 | const int T_alto=1630; |
jaruiz | 0:a2790441065a | 20 | const int T_bajo=533; |
jaruiz | 0:a2790441065a | 21 | const int num_bits = 24; |
jaruiz | 0:a2790441065a | 22 | int num[num_bits]; |
jaruiz | 0:a2790441065a | 23 | |
jaruiz | 0:a2790441065a | 24 | |
jaruiz | 0:a2790441065a | 25 | // TECLAS PROGRAMADAS |
jaruiz | 0:a2790441065a | 26 | |
jaruiz | 0:a2790441065a | 27 | int Tecla=0; |
jaruiz | 0:a2790441065a | 28 | const int T1=102; |
jaruiz | 0:a2790441065a | 29 | const int T2=94; |
jaruiz | 0:a2790441065a | 30 | const int T3=90; |
jaruiz | 0:a2790441065a | 31 | const int T4=82; |
jaruiz | 0:a2790441065a | 32 | const int T5=150; |
jaruiz | 0:a2790441065a | 33 | const int T6=84; |
jaruiz | 0:a2790441065a | 34 | |
jaruiz | 0:a2790441065a | 35 | |
jaruiz | 0:a2790441065a | 36 | int dato; // tiempo de cada dato que se lee |
jaruiz | 0:a2790441065a | 37 | |
jaruiz | 0:a2790441065a | 38 | int main() |
jaruiz | 0:a2790441065a | 39 | { |
jaruiz | 0:a2790441065a | 40 | |
jaruiz | 0:a2790441065a | 41 | led=1; |
jaruiz | 0:a2790441065a | 42 | led2=1; |
jaruiz | 0:a2790441065a | 43 | led3=1; |
jaruiz | 0:a2790441065a | 44 | while(1) |
jaruiz | 0:a2790441065a | 45 | { |
jaruiz | 0:a2790441065a | 46 | lcd.cls(); |
jaruiz | 0:a2790441065a | 47 | lcd.locate(0,0); |
jaruiz | 0:a2790441065a | 48 | lcd.printf("ESPERANDO ORDEN"); |
jaruiz | 0:a2790441065a | 49 | |
jaruiz | 0:a2790441065a | 50 | |
jaruiz | 0:a2790441065a | 51 | |
jaruiz | 0:a2790441065a | 52 | ini1: fflush( stdin ); |
jaruiz | 0:a2790441065a | 53 | header=0; |
jaruiz | 0:a2790441065a | 54 | header = irda.read_low_us(); |
jaruiz | 0:a2790441065a | 55 | if (header > head_L && header < head_H) goto seguir; |
jaruiz | 0:a2790441065a | 56 | else goto ini1; |
jaruiz | 0:a2790441065a | 57 | |
jaruiz | 0:a2790441065a | 58 | seguir: |
jaruiz | 0:a2790441065a | 59 | |
jaruiz | 0:a2790441065a | 60 | wait_us(4500); |
jaruiz | 0:a2790441065a | 61 | lcd.cls(); |
jaruiz | 0:a2790441065a | 62 | Tecla=0; |
jaruiz | 0:a2790441065a | 63 | for(i=0;i<(num_bits-1);++i) |
jaruiz | 0:a2790441065a | 64 | { |
jaruiz | 0:a2790441065a | 65 | dato = irda.read_high_us(); |
jaruiz | 0:a2790441065a | 66 | num[i]=dato; |
jaruiz | 0:a2790441065a | 67 | wait_us(Tp); |
jaruiz | 0:a2790441065a | 68 | } |
jaruiz | 0:a2790441065a | 69 | wait(0.3); |
jaruiz | 0:a2790441065a | 70 | |
jaruiz | 0:a2790441065a | 71 | for(i=0;i<(num_bits-1);++i) |
jaruiz | 0:a2790441065a | 72 | { |
jaruiz | 0:a2790441065a | 73 | |
jaruiz | 0:a2790441065a | 74 | if(num[i] > ((T_alto+T_bajo)/2)) |
jaruiz | 0:a2790441065a | 75 | { |
jaruiz | 0:a2790441065a | 76 | Tecla=Tecla+ (2^(i)); |
jaruiz | 0:a2790441065a | 77 | } |
jaruiz | 0:a2790441065a | 78 | } |
jaruiz | 0:a2790441065a | 79 | if(Tecla==T1) |
jaruiz | 0:a2790441065a | 80 | { led=!led; |
jaruiz | 0:a2790441065a | 81 | lcd.cls(); |
jaruiz | 0:a2790441065a | 82 | lcd.printf("A: ON RIGHT"); |
jaruiz | 0:a2790441065a | 83 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 84 | lcd.printf("Codigo=%d",Tecla); |
jaruiz | 0:a2790441065a | 85 | wait(1.5); |
jaruiz | 0:a2790441065a | 86 | lcd.cls(); |
jaruiz | 0:a2790441065a | 87 | lcd.locate(0,0); |
jaruiz | 0:a2790441065a | 88 | lcd.printf("HH:%d",head_H); |
jaruiz | 0:a2790441065a | 89 | lcd.locate(8,0); |
jaruiz | 0:a2790441065a | 90 | lcd.printf("Tby:%d",Tp); |
jaruiz | 0:a2790441065a | 91 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 92 | lcd.printf("HL:%d",head_L); |
jaruiz | 0:a2790441065a | 93 | lcd.locate(8,1); |
jaruiz | 0:a2790441065a | 94 | lcd.printf("Nby:%d",num_bits); |
jaruiz | 0:a2790441065a | 95 | wait(1.5); |
jaruiz | 0:a2790441065a | 96 | Tecla=0; |
jaruiz | 0:a2790441065a | 97 | } |
jaruiz | 0:a2790441065a | 98 | if(Tecla==T2) |
jaruiz | 0:a2790441065a | 99 | { |
jaruiz | 0:a2790441065a | 100 | led2=!led2; |
jaruiz | 0:a2790441065a | 101 | lcd.cls(); |
jaruiz | 0:a2790441065a | 102 | lcd.printf("B: STOP"); |
jaruiz | 0:a2790441065a | 103 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 104 | lcd.printf("Codigo=%d",Tecla); |
jaruiz | 0:a2790441065a | 105 | wait(1.5); |
jaruiz | 0:a2790441065a | 106 | lcd.cls(); |
jaruiz | 0:a2790441065a | 107 | lcd.locate(0,0); |
jaruiz | 0:a2790441065a | 108 | lcd.printf("HH:%d",head_H); |
jaruiz | 0:a2790441065a | 109 | lcd.locate(8,0); |
jaruiz | 0:a2790441065a | 110 | lcd.printf("Tby:%d",Tp); |
jaruiz | 0:a2790441065a | 111 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 112 | lcd.printf("HL:%d",head_L); |
jaruiz | 0:a2790441065a | 113 | lcd.locate(8,1); |
jaruiz | 0:a2790441065a | 114 | lcd.printf("Nby:%d",num_bits); |
jaruiz | 0:a2790441065a | 115 | Tecla=0; |
jaruiz | 0:a2790441065a | 116 | wait(1.5); |
jaruiz | 0:a2790441065a | 117 | } |
jaruiz | 0:a2790441065a | 118 | if(Tecla==T3) |
jaruiz | 0:a2790441065a | 119 | { |
jaruiz | 0:a2790441065a | 120 | |
jaruiz | 0:a2790441065a | 121 | led3=!led3; |
jaruiz | 0:a2790441065a | 122 | lcd.cls(); |
jaruiz | 0:a2790441065a | 123 | lcd.printf("C: ON LEFT"); |
jaruiz | 0:a2790441065a | 124 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 125 | lcd.printf("Codigo=%d",Tecla); |
jaruiz | 0:a2790441065a | 126 | wait(1.5); |
jaruiz | 0:a2790441065a | 127 | lcd.cls(); |
jaruiz | 0:a2790441065a | 128 | lcd.locate(0,0); |
jaruiz | 0:a2790441065a | 129 | lcd.printf("HH:%d",head_H); |
jaruiz | 0:a2790441065a | 130 | lcd.locate(8,0); |
jaruiz | 0:a2790441065a | 131 | lcd.printf("Tby:%d",Tp); |
jaruiz | 0:a2790441065a | 132 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 133 | lcd.printf("HL:%d",head_L); |
jaruiz | 0:a2790441065a | 134 | lcd.locate(8,1); |
jaruiz | 0:a2790441065a | 135 | lcd.printf("Nby:%d",num_bits); |
jaruiz | 0:a2790441065a | 136 | Tecla=0; |
jaruiz | 0:a2790441065a | 137 | wait(1.5); |
jaruiz | 0:a2790441065a | 138 | } |
jaruiz | 0:a2790441065a | 139 | if(Tecla==T4) |
jaruiz | 0:a2790441065a | 140 | { |
jaruiz | 0:a2790441065a | 141 | |
jaruiz | 0:a2790441065a | 142 | Vout=2.5; |
jaruiz | 0:a2790441065a | 143 | wait(0.2); |
jaruiz | 0:a2790441065a | 144 | Vout=0; |
jaruiz | 0:a2790441065a | 145 | lcd.cls(); |
jaruiz | 0:a2790441065a | 146 | lcd.printf("D:Boton otra func"); |
jaruiz | 0:a2790441065a | 147 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 148 | lcd.printf("Codigo=%d",Tecla); |
jaruiz | 0:a2790441065a | 149 | wait(1.5); |
jaruiz | 0:a2790441065a | 150 | lcd.cls(); |
jaruiz | 0:a2790441065a | 151 | lcd.locate(0,0); |
jaruiz | 0:a2790441065a | 152 | lcd.printf("HH:%d",head_H); |
jaruiz | 0:a2790441065a | 153 | lcd.locate(8,0); |
jaruiz | 0:a2790441065a | 154 | lcd.printf("Tby:%d",Tp); |
jaruiz | 0:a2790441065a | 155 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 156 | lcd.printf("HL:%d",head_L); |
jaruiz | 0:a2790441065a | 157 | lcd.locate(8,1); |
jaruiz | 0:a2790441065a | 158 | lcd.printf("Nby:%d",num_bits); |
jaruiz | 0:a2790441065a | 159 | Tecla=0; |
jaruiz | 0:a2790441065a | 160 | wait(1.5); |
jaruiz | 0:a2790441065a | 161 | } |
jaruiz | 0:a2790441065a | 162 | |
jaruiz | 0:a2790441065a | 163 | if(Tecla==T5) |
jaruiz | 0:a2790441065a | 164 | { |
jaruiz | 0:a2790441065a | 165 | Vout=2.5; |
jaruiz | 0:a2790441065a | 166 | wait(0.07); |
jaruiz | 0:a2790441065a | 167 | Vout=0; |
jaruiz | 0:a2790441065a | 168 | wait(0.03); |
jaruiz | 0:a2790441065a | 169 | Vout=2.5; |
jaruiz | 0:a2790441065a | 170 | wait(0.07); |
jaruiz | 0:a2790441065a | 171 | Vout=0; |
jaruiz | 0:a2790441065a | 172 | wait(0.03); |
jaruiz | 0:a2790441065a | 173 | Vout=2.5; |
jaruiz | 0:a2790441065a | 174 | wait(0.07); |
jaruiz | 0:a2790441065a | 175 | Vout=0; |
jaruiz | 0:a2790441065a | 176 | led2=!led2; |
jaruiz | 0:a2790441065a | 177 | lcd.cls(); |
jaruiz | 0:a2790441065a | 178 | lcd.printf("ENCENDER 1"); |
jaruiz | 0:a2790441065a | 179 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 180 | lcd.printf("Codigo=%d",Tecla); |
jaruiz | 0:a2790441065a | 181 | wait(1.5); |
jaruiz | 0:a2790441065a | 182 | lcd.cls(); |
jaruiz | 0:a2790441065a | 183 | |
jaruiz | 0:a2790441065a | 184 | } |
jaruiz | 0:a2790441065a | 185 | |
jaruiz | 0:a2790441065a | 186 | if(Tecla==T6) |
jaruiz | 0:a2790441065a | 187 | { |
jaruiz | 0:a2790441065a | 188 | Vout=2.5; |
jaruiz | 0:a2790441065a | 189 | wait(0.07); |
jaruiz | 0:a2790441065a | 190 | Vout=0; |
jaruiz | 0:a2790441065a | 191 | wait(0.03); |
jaruiz | 0:a2790441065a | 192 | Vout=2.5; |
jaruiz | 0:a2790441065a | 193 | wait(0.07); |
jaruiz | 0:a2790441065a | 194 | Vout=0; |
jaruiz | 0:a2790441065a | 195 | |
jaruiz | 0:a2790441065a | 196 | led3=!led3; |
jaruiz | 0:a2790441065a | 197 | lcd.cls(); |
jaruiz | 0:a2790441065a | 198 | lcd.printf("ENCENDER 2"); |
jaruiz | 0:a2790441065a | 199 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 200 | lcd.printf("Codigo=%d",Tecla); |
jaruiz | 0:a2790441065a | 201 | wait(1.5); |
jaruiz | 0:a2790441065a | 202 | lcd.cls(); |
jaruiz | 0:a2790441065a | 203 | |
jaruiz | 0:a2790441065a | 204 | } |
jaruiz | 0:a2790441065a | 205 | if ((Tecla!=T3)&&(Tecla!=T2)&&(Tecla!=T1)&&(Tecla!=0)&&(Tecla!=T4)&&(Tecla!=T5)&&(Tecla!=T6)){ |
jaruiz | 0:a2790441065a | 206 | lcd.cls(); |
jaruiz | 0:a2790441065a | 207 | lcd.printf("SIN FUNCION"); |
jaruiz | 0:a2790441065a | 208 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 209 | lcd.printf("Codigo=%d",Tecla); |
jaruiz | 0:a2790441065a | 210 | wait(2); |
jaruiz | 0:a2790441065a | 211 | lcd.cls(); |
jaruiz | 0:a2790441065a | 212 | lcd.locate(0,0); |
jaruiz | 0:a2790441065a | 213 | lcd.printf("HH:%d",head_H); |
jaruiz | 0:a2790441065a | 214 | lcd.locate(8,0); |
jaruiz | 0:a2790441065a | 215 | lcd.printf("Tby:%d",Tp); |
jaruiz | 0:a2790441065a | 216 | lcd.locate(0,1); |
jaruiz | 0:a2790441065a | 217 | lcd.printf("HL:%d",head_L); |
jaruiz | 0:a2790441065a | 218 | lcd.locate(8,1); |
jaruiz | 0:a2790441065a | 219 | lcd.printf("Nby:%d",num_bits); |
jaruiz | 0:a2790441065a | 220 | Tecla=0; |
jaruiz | 0:a2790441065a | 221 | wait(1.5);} |
jaruiz | 0:a2790441065a | 222 | } |
jaruiz | 0:a2790441065a | 223 | } |