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.
Control.cpp
00001 #include "mbed.h" 00002 #include <Pulse1.h> 00003 00004 PulseInOut irda(PTD5); 00005 Serial pc(USBTX, USBRX); 00006 DigitalOut l0(LED1); 00007 DigitalOut l1(LED2); 00008 DigitalOut l2(LED3); 00009 00010 int header =0; 00011 const int head_H = 2964; //+20% medida con osciloscopio en microsegundos 00012 const int head_L = 1976;//-20% medida con osciloscopio 00013 int i=0; 00014 const int T_alto=1200;//ponga su tiempo de la prueba 00015 const int T_bajo=600;//ponga su tiempo de la prueba 00016 const int num_bits = 21;//ponga su numero de bits 00017 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos 00018 int dato; // tiempo de cada dato que se lee 00019 int n1[20],n2[20],n3[20]; 00020 00021 int main(){ 00022 n1[0]=n1[1]=n1[2]=n1[3]=n1[4]=n1[5]=n1[6]=n1[7]=n1[9]=n1[13]=n1[14]=n1[16]=n1[17]=n1[19]=0; 00023 n1[8]=n1[10]=n1[11]=n1[12]=n1[15]=n1[18]=1; 00024 n2[1]=n2[3]=n2[4]=n2[5]=n2[6]=n2[7]=n2[1]=n2[9]=n2[13]=n2[14]=n2[16]=n2[17]=n2[19]=0; 00025 n2[8]=n2[10]=n2[11]=n2[12]=n2[15]=n2[18]=n2[0]=1; 00026 n3[0]=n3[2]=n3[3]=n3[4]=n3[5]=n3[6]=n3[7]=n3[9]=n3[13]=n3[14]=n3[16]=n3[17]=n3[19]=0; 00027 n3[8]=n3[10]=n3[11]=n3[12]=n3[15]=n3[18]=n3[1]=1; 00028 int w,e,r; 00029 w=e=r=0; 00030 l0=l1=l2=1; 00031 while(1){ 00032 ini1: header=0; 00033 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo 00034 if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% 00035 else goto ini1; 00036 00037 seguir: 00038 wait_us(300); 00039 00040 for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos 00041 dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control 00042 num[i]=dato; 00043 wait_us(300); 00044 } 00045 00046 wait(0.5); //espero un poquito antes de leer todo el arreglo y ponerlo en pantalla 00047 00048 for(i=0;i<(num_bits-1);++i){ 00049 if(num[i] > ((T_alto+T_bajo)/2)) num[i]=1; 00050 else num[i]=0; 00051 } 00052 for(i=0;i<(num_bits-1);++i){ 00053 if(num[i]==n1[i])w++; 00054 } 00055 00056 if(w==20){ 00057 l0=!l0; 00058 } 00059 for(i=0;i<(num_bits-1);++i){ 00060 if(num[i]==n2[i])e++; 00061 } 00062 00063 if(e==20){ 00064 l1=!l1; 00065 } 00066 for(i=0;i<(num_bits-1);++i){ 00067 if(num[i]==n3[i])r++; 00068 } 00069 00070 if(r==20){ 00071 l2=!l2; 00072 } 00073 w=e=r=0; 00074 } 00075 }
Generated on Sat Aug 13 2022 05:45:01 by
1.7.2