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: Pulse1 TextLCD mbed
Fork of irda_V_aula by
main.cpp
00001 // Santiago Lopez Restrepo 00002 // Diego Fernando Carvajal Castrillon 00003 00004 #include "mbed.h" 00005 #include <Pulse1.h> 00006 #include "TextLCD.h" 00007 00008 00009 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7#include "TextLCD.h" 00010 //control remoto videobeam aula 00011 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo 00012 DigitalOut led(LED1); 00013 DigitalOut led2(LED2); 00014 DigitalOut led3(LED3); 00015 00016 int header =0; //tiempo de cabecera pulso abajo 00017 const int head_H = 9120; //+10% medida con osciloscopio en microsegundos 00018 const int head_L = 8939;//-10% medida con osciloscopio 00019 const int Tp=300; 00020 int i=0; 00021 const int T_alto=1570;//1630;//ponga su tiempo de la prueba 00022 const int T_bajo=467;//533;//ponga su tiempo de la prueba 00023 const int num_bits = 24;//ponga su numero de bits 00024 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos 00025 00026 int Tecla=0; 00027 const int N1=96; 00028 const int N2=117; 00029 const int N3=109; 00030 00031 int dato; // tiempo de cada dato que se lee 00032 00033 int main() 00034 { 00035 00036 led=1; 00037 led2=1; 00038 led3=1; 00039 while(1) 00040 { 00041 00042 00043 00044 lcd.cls(); 00045 lcd.locate(0,0); 00046 lcd.printf("PRESIONE TECLA"); 00047 00048 ini1: fflush( stdin ); 00049 header=0; 00050 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header 00051 if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% 00052 else goto ini1; 00053 00054 seguir: 00055 //leo los datos de la trama y se meten a un arreglo 00056 wait_us(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 00057 //led2=0; 00058 lcd.cls(); 00059 Tecla=0; 00060 for(i=0;i<(num_bits-1);++i) 00061 { // POR OSCILOSCOPIO se determina que llegan (num_bits),datos 00062 dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control 00063 num[i]=dato; 00064 wait_us(Tp); 00065 } 00066 wait(0.3); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla 00067 00068 for(i=0;i<(num_bits-1);++i) 00069 { 00070 00071 if(num[i] > ((T_alto+T_bajo)/2)) 00072 { 00073 Tecla=Tecla+ (2^(i)); 00074 } 00075 00076 } 00077 if(Tecla==N1) 00078 { led=!led; 00079 lcd.cls(); 00080 lcd.printf("PRESIONASTE 1"); 00081 lcd.locate(0,1); 00082 lcd.printf("Codigo=%d",Tecla); 00083 wait(2); 00084 lcd.cls(); 00085 lcd.locate(0,0); 00086 lcd.printf("HH:%d",head_H); 00087 lcd.locate(8,0); 00088 lcd.printf("Tby:%d",Tp); 00089 lcd.locate(0,1); 00090 lcd.printf("HL:%d",head_L); 00091 lcd.locate(8,1); 00092 lcd.printf("Nby:%d",num_bits); 00093 wait(2); 00094 Tecla=0; 00095 } 00096 if(Tecla==N2) 00097 { 00098 led2=!led2; 00099 lcd.cls(); 00100 lcd.printf("PRESIONASTE 2"); 00101 lcd.locate(0,1); 00102 lcd.printf("Codigo=%d",Tecla); 00103 wait(2); 00104 lcd.cls(); 00105 lcd.locate(0,0); 00106 lcd.printf("HH:%d",head_H); 00107 lcd.locate(8,0); 00108 lcd.printf("Tby:%d",Tp); 00109 lcd.locate(0,1); 00110 lcd.printf("HL:%d",head_L); 00111 lcd.locate(8,1); 00112 lcd.printf("Nby:%d",num_bits); 00113 Tecla=0; 00114 wait(2); 00115 } 00116 if(Tecla==N3) 00117 { 00118 00119 led3=!led3; 00120 lcd.cls(); 00121 lcd.printf("PRESIONASTE 3"); 00122 lcd.locate(0,1); 00123 lcd.printf("Codigo=%d",Tecla); 00124 wait(2); 00125 lcd.cls(); 00126 lcd.locate(0,0); 00127 lcd.printf("HH:%d",head_H); 00128 lcd.locate(8,0); 00129 lcd.printf("Tby:%d",Tp); 00130 lcd.locate(0,1); 00131 lcd.printf("HL:%d",head_L); 00132 lcd.locate(8,1); 00133 lcd.printf("Nby:%d",num_bits); 00134 Tecla=0; 00135 wait(2); 00136 } 00137 if ((Tecla!=N3)&&(Tecla!=N2)&&(Tecla!=N1)&&(Tecla!=0)){ 00138 lcd.cls(); 00139 lcd.printf("TECLA INCORRECTA"); 00140 lcd.locate(0,1); 00141 lcd.printf("Codigo=%d",Tecla); 00142 wait(2); 00143 lcd.cls(); 00144 lcd.locate(0,0); 00145 lcd.printf("HH:%d",head_H); 00146 lcd.locate(8,0); 00147 lcd.printf("Tby:%d",Tp); 00148 lcd.locate(0,1); 00149 lcd.printf("HL:%d",head_L); 00150 lcd.locate(8,1); 00151 lcd.printf("Nby:%d",num_bits); 00152 Tecla=0; 00153 wait(2);} 00154 } 00155 }
Generated on Tue Jul 19 2022 01:26:57 by
1.7.2
