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 irda1 by
main.cpp
00001 #include "mbed.h" 00002 #include <Pulse1.h> 00003 #include "TextLCD.h" 00004 00005 00006 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00007 PulseInOut irda(PTD5); 00008 Serial pc(USBTX, USBRX); 00009 DigitalOut led1(LED1); 00010 DigitalOut led2(LED2); 00011 DigitalOut led3(LED3); 00012 00013 int header =0; 00014 const int head_H = 10884; //+20% medida con osciloscopio en microsegundos (cabecera) 00015 const int head_L = 7256;//-20% medida con osciloscopio 00016 int i=0; 00017 const int T_alto=1670;//ponga su tiempo de la prueba 00018 const int T_bajo=533;//ponga su tiempo de la prueba 00019 const int num_bits = 32;//ponga su numero de bits 00020 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos 00021 int dato; // tiempo de cada dato que se lee 00022 int n1[32],n2[32],n3[32]; 00023 int cont1,cont2,cont3; 00024 int main(){ 00025 //tecla1 00026 n1[0]=n1[5]=n1[6]=n1[9]=n1[10]=n1[12]=n1[14]=n1[15]=n1[18]=n1[24]=n1[25]=n1[27]=n1[28]=n1[29]=n1[30]=1; 00027 n1[1]=n1[2]=n1[3]=n1[4]=n1[7]=n1[8]=n1[11]=n1[13]=n1[16]=n1[17]=n1[19]=n1[20]=n1[21]=n1[22]=n1[23]=n1[26]=0;n1[31]=0; 00028 n2[0]=n2[5]=n2[6]=n2[9]=n2[10]=n2[12]=n2[14]=n2[15]=n2[17]=n2[24]=n2[26]=n2[27]=n2[28]=n2[29]=n2[30]=1; 00029 n2[1]=n2[2]=n2[3]=n2[4]=n2[7]=n2[8]=n2[11]=n2[13]=n2[16]=n2[18]=n2[19]=n2[20]=n2[21]=n2[22]=n2[23]=n2[25]=0;n2[31]=0; 00030 n3[0]=n3[5]=n3[6]=n3[9]=n3[10]=n3[12]=n3[14]=n3[15]=n3[16]=n3[18]=n3[25]=n3[27]=n3[28]=n3[29]=n3[30]=1; 00031 n3[1]=n3[2]=n3[3]=n3[4]=n3[7]=n3[8]=n3[11]=n3[13]=n3[17]=n3[19]=n3[20]=n3[21]=n3[22]=n3[23]=n3[24]=n3[26]=0;n3[31]=0; 00032 00033 cont1=cont2=cont3=0; 00034 led1=1; 00035 led2=1; 00036 led3=1; 00037 00038 while(1){ 00039 ini1: header=0; 00040 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo 00041 if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% 00042 else goto ini1; 00043 00044 seguir: 00045 wait_us(2000); 00046 00047 for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos 00048 dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control 00049 num[i]=dato; 00050 wait_us(633); 00051 } 00052 00053 wait(0.5);//spero un poquito antes de leer todo el arreglo y ponerlo en pantalla 00054 00055 for(i=0;i<(num_bits-1);++i){ 00056 if(num[i] > ((T_alto+T_bajo)/2)) { 00057 num[i]=1; 00058 //led1=0; 00059 } 00060 else num[i]=0; 00061 //led1=0; 00062 } 00063 for(i=0;i<(num_bits-1);++i){ 00064 if(num[i]==n1[i]){ 00065 cont1++; 00066 led2=0; 00067 } 00068 } 00069 led2=1; 00070 if(cont1==31){ 00071 led1=0; 00072 lcd.cls(); // Borrar Pantalla 00073 lcd.locate(0,0); 00074 lcd.printf("Ha presionado el boton 1 "); //si coincidieron todos los bits del boton 1 00075 } 00076 00077 00078 for(i=0;i<(num_bits-1);++i){ 00079 if(num[i]==n2[i]){ 00080 cont2++; 00081 led2=1; 00082 } 00083 } 00084 00085 if(cont2==10){ 00086 led2=!led2; 00087 lcd.cls(); // Borrar Pantalla 00088 lcd.locate(0,0); 00089 lcd.printf("Ha presionado el boton 3 "); //si coincidieron todos los bits del boton 1 00090 00091 } 00092 for(i=0;i<(num_bits-1);++i){ 00093 if(num[i]==n3[i]) 00094 cont3++; 00095 led3=0; 00096 } 00097 00098 if(cont3==10){ 00099 led3=!led3; 00100 lcd.cls(); // Borrar Pantalla 00101 lcd.locate(0,0); 00102 lcd.printf("Ha presionado el boton 5"); //si coincidieron todos los bits del boton 1 00103 } 00104 00105 cont1=0; 00106 cont2=0; 00107 cont3=0; 00108 } 00109 }
Generated on Sat Jul 23 2022 10:06:59 by
1.7.2
