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
00001 #include "mbed.h" 00002 #include <Pulse1.h> 00003 #include "TextLCD.h" 00004 #include "DebouncedIn.h" 00005 00006 00007 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); 00008 PulseInOut irda(PTD5); 00009 DigitalOut led(LED1); // LED ROJO 00010 DigitalOut led2(LED2);// LED VERDE 00011 DigitalOut led3(LED3); // LED AZUL 00012 AnalogOut Vout(PTE30); // SALIDA SONIDO 00013 00014 int header =0; // Tiempo Cabecera 00015 const int head_H = 9120; //+10% OSCILOSCOPIO 00016 const int head_L = 8939;//-10% OSCILOSCOPIO 00017 const int Tp=300; 00018 int i=0; 00019 const int T_alto=1630; 00020 const int T_bajo=533; 00021 const int num_bits = 24; 00022 int num[num_bits]; 00023 00024 00025 // TECLAS PROGRAMADAS 00026 00027 int Tecla=0; 00028 const int T1=102; 00029 const int T2=94; 00030 const int T3=90; 00031 const int T4=82; 00032 const int T5=150; 00033 const int T6=84; 00034 00035 00036 int dato; // tiempo de cada dato que se lee 00037 00038 int main() 00039 { 00040 00041 led=1; 00042 led2=1; 00043 led3=1; 00044 while(1) 00045 { 00046 lcd.cls(); 00047 lcd.locate(0,0); 00048 lcd.printf("ESPERANDO ORDEN"); 00049 00050 00051 00052 ini1: fflush( stdin ); 00053 header=0; 00054 header = irda.read_low_us(); 00055 if (header > head_L && header < head_H) goto seguir; 00056 else goto ini1; 00057 00058 seguir: 00059 00060 wait_us(4500); 00061 lcd.cls(); 00062 Tecla=0; 00063 for(i=0;i<(num_bits-1);++i) 00064 { 00065 dato = irda.read_high_us(); 00066 num[i]=dato; 00067 wait_us(Tp); 00068 } 00069 wait(0.3); 00070 00071 for(i=0;i<(num_bits-1);++i) 00072 { 00073 00074 if(num[i] > ((T_alto+T_bajo)/2)) 00075 { 00076 Tecla=Tecla+ (2^(i)); 00077 } 00078 } 00079 if(Tecla==T1) 00080 { led=!led; 00081 lcd.cls(); 00082 lcd.printf("A: ON RIGHT"); 00083 lcd.locate(0,1); 00084 lcd.printf("Codigo=%d",Tecla); 00085 wait(1.5); 00086 lcd.cls(); 00087 lcd.locate(0,0); 00088 lcd.printf("HH:%d",head_H); 00089 lcd.locate(8,0); 00090 lcd.printf("Tby:%d",Tp); 00091 lcd.locate(0,1); 00092 lcd.printf("HL:%d",head_L); 00093 lcd.locate(8,1); 00094 lcd.printf("Nby:%d",num_bits); 00095 wait(1.5); 00096 Tecla=0; 00097 } 00098 if(Tecla==T2) 00099 { 00100 led2=!led2; 00101 lcd.cls(); 00102 lcd.printf("B: STOP"); 00103 lcd.locate(0,1); 00104 lcd.printf("Codigo=%d",Tecla); 00105 wait(1.5); 00106 lcd.cls(); 00107 lcd.locate(0,0); 00108 lcd.printf("HH:%d",head_H); 00109 lcd.locate(8,0); 00110 lcd.printf("Tby:%d",Tp); 00111 lcd.locate(0,1); 00112 lcd.printf("HL:%d",head_L); 00113 lcd.locate(8,1); 00114 lcd.printf("Nby:%d",num_bits); 00115 Tecla=0; 00116 wait(1.5); 00117 } 00118 if(Tecla==T3) 00119 { 00120 00121 led3=!led3; 00122 lcd.cls(); 00123 lcd.printf("C: ON LEFT"); 00124 lcd.locate(0,1); 00125 lcd.printf("Codigo=%d",Tecla); 00126 wait(1.5); 00127 lcd.cls(); 00128 lcd.locate(0,0); 00129 lcd.printf("HH:%d",head_H); 00130 lcd.locate(8,0); 00131 lcd.printf("Tby:%d",Tp); 00132 lcd.locate(0,1); 00133 lcd.printf("HL:%d",head_L); 00134 lcd.locate(8,1); 00135 lcd.printf("Nby:%d",num_bits); 00136 Tecla=0; 00137 wait(1.5); 00138 } 00139 if(Tecla==T4) 00140 { 00141 00142 Vout=2.5; 00143 wait(0.2); 00144 Vout=0; 00145 lcd.cls(); 00146 lcd.printf("D:Boton otra func"); 00147 lcd.locate(0,1); 00148 lcd.printf("Codigo=%d",Tecla); 00149 wait(1.5); 00150 lcd.cls(); 00151 lcd.locate(0,0); 00152 lcd.printf("HH:%d",head_H); 00153 lcd.locate(8,0); 00154 lcd.printf("Tby:%d",Tp); 00155 lcd.locate(0,1); 00156 lcd.printf("HL:%d",head_L); 00157 lcd.locate(8,1); 00158 lcd.printf("Nby:%d",num_bits); 00159 Tecla=0; 00160 wait(1.5); 00161 } 00162 00163 if(Tecla==T5) 00164 { 00165 Vout=2.5; 00166 wait(0.07); 00167 Vout=0; 00168 wait(0.03); 00169 Vout=2.5; 00170 wait(0.07); 00171 Vout=0; 00172 wait(0.03); 00173 Vout=2.5; 00174 wait(0.07); 00175 Vout=0; 00176 led2=!led2; 00177 lcd.cls(); 00178 lcd.printf("ENCENDER 1"); 00179 lcd.locate(0,1); 00180 lcd.printf("Codigo=%d",Tecla); 00181 wait(1.5); 00182 lcd.cls(); 00183 00184 } 00185 00186 if(Tecla==T6) 00187 { 00188 Vout=2.5; 00189 wait(0.07); 00190 Vout=0; 00191 wait(0.03); 00192 Vout=2.5; 00193 wait(0.07); 00194 Vout=0; 00195 00196 led3=!led3; 00197 lcd.cls(); 00198 lcd.printf("ENCENDER 2"); 00199 lcd.locate(0,1); 00200 lcd.printf("Codigo=%d",Tecla); 00201 wait(1.5); 00202 lcd.cls(); 00203 00204 } 00205 if ((Tecla!=T3)&&(Tecla!=T2)&&(Tecla!=T1)&&(Tecla!=0)&&(Tecla!=T4)&&(Tecla!=T5)&&(Tecla!=T6)){ 00206 lcd.cls(); 00207 lcd.printf("SIN FUNCION"); 00208 lcd.locate(0,1); 00209 lcd.printf("Codigo=%d",Tecla); 00210 wait(2); 00211 lcd.cls(); 00212 lcd.locate(0,0); 00213 lcd.printf("HH:%d",head_H); 00214 lcd.locate(8,0); 00215 lcd.printf("Tby:%d",Tp); 00216 lcd.locate(0,1); 00217 lcd.printf("HL:%d",head_L); 00218 lcd.locate(8,1); 00219 lcd.printf("Nby:%d",num_bits); 00220 Tecla=0; 00221 wait(1.5);} 00222 } 00223 }
Generated on Tue Aug 30 2022 09:11:47 by 1.7.2