control remoto infrarojo

Dependencies:   Pulse1 mbed

Committer:
salondonog
Date:
Thu Dec 05 21:06:26 2013 +0000
Revision:
0:b577167f506e
Infrarojo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
salondonog 0:b577167f506e 1 #include "mbed.h"
salondonog 0:b577167f506e 2 #include <Pulse1.h>
salondonog 0:b577167f506e 3
salondonog 0:b577167f506e 4 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
salondonog 0:b577167f506e 5 Serial pc(USBTX, USBRX);
salondonog 0:b577167f506e 6 DigitalOut led2_G(LED2);
salondonog 0:b577167f506e 7 DigitalOut led2_R(LED3);
salondonog 0:b577167f506e 8 DigitalOut led2_B(LED1);
salondonog 0:b577167f506e 9 int header =0; //tiempo de cabecera pulso abajo
salondonog 0:b577167f506e 10 const int head_H = 3550*1.2; //+20% medida con osciloscopio en microsegundos
salondonog 0:b577167f506e 11 const int head_L = 3550*0.8;//-20% medida con osciloscopio
salondonog 0:b577167f506e 12 int i=0;
salondonog 0:b577167f506e 13 int n=0;
salondonog 0:b577167f506e 14 const int T_alto=1200;//ponga su tiempo de la prueba
salondonog 0:b577167f506e 15 const int T_bajo=333;//ponga su tiempo de la prueba
salondonog 0:b577167f506e 16 const int num_bits = 48;//ponga su numero de bits
salondonog 0:b577167f506e 17 int arreglo[num_bits];
salondonog 0:b577167f506e 18 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
salondonog 0:b577167f506e 19 int dato; // tiempo de cada dato que se lee
salondonog 0:b577167f506e 20 int boton1[num_bits]; //Datos del control tecla 1
salondonog 0:b577167f506e 21 int boton2[num_bits]; //Datos del control tecla 2
salondonog 0:b577167f506e 22 int boton3[num_bits]; //Datos del control tecla 3
salondonog 0:b577167f506e 23
salondonog 0:b577167f506e 24 void conf_botones(void){
salondonog 0:b577167f506e 25 boton1[0]=0; boton1[1]=1; boton1[2]=0; boton1[3]=0; boton1[4]=0; boton1[5]=0; boton1[6]=0; boton1[7]=0; boton1[8]=0;
salondonog 0:b577167f506e 26 boton1[9]=0; boton1[10]=0; boton1[11]=0; boton1[12]=0; boton1[13]=1; boton1[14]=0; boton1[15]=0; boton1[16]=0; boton1[17]=0;
salondonog 0:b577167f506e 27 boton1[18]=0; boton1[19]=0; boton1[20]=0; boton1[21]=1; boton1[22]=0; boton1[23]=1; boton1[24]=0; boton1[25]=0; boton1[26]=1;
salondonog 0:b577167f506e 28 boton1[27]=1; boton1[28]=1; boton1[29]=0; boton1[30]=0; boton1[31]=0; boton1[32]=0; boton1[33]=0; boton1[34]=0; boton1[35]=0;
salondonog 0:b577167f506e 29 boton1[36]=1; boton1[37]=0; boton1[38]=0; boton1[39]=0; boton1[40]=0; boton1[41]=0; boton1[42]=1; boton1[43]=1; boton1[44]=0;
salondonog 0:b577167f506e 30 boton1[45]=1; boton1[46]=0; boton1[47]=1;
salondonog 0:b577167f506e 31
salondonog 0:b577167f506e 32 boton2[0]=0; boton2[1]=1; boton2[2]=0; boton2[3]=0; boton2[4]=0; boton2[5]=0; boton2[6]=0; boton2[7]=0; boton2[8]=0;
salondonog 0:b577167f506e 33 boton2[9]=0; boton2[10]=0; boton2[11]=0; boton2[12]=0; boton2[13]=1; boton2[14]=0; boton2[15]=0; boton2[16]=0; boton2[17]=0;
salondonog 0:b577167f506e 34 boton2[18]=0; boton2[19]=0; boton2[20]=0; boton2[21]=1; boton2[22]=0; boton2[23]=1; boton2[24]=0; boton2[25]=0; boton2[26]=1;
salondonog 0:b577167f506e 35 boton2[27]=1; boton2[28]=1; boton2[29]=0; boton2[30]=0; boton2[31]=0; boton2[32]=1; boton2[33]=0; boton2[34]=0; boton2[35]=0;
salondonog 0:b577167f506e 36 boton2[36]=1; boton2[37]=0; boton2[38]=0; boton2[39]=0; boton2[40]=1; boton2[41]=0; boton2[42]=1; boton2[43]=1; boton2[44]=0;
salondonog 0:b577167f506e 37 boton2[45]=1; boton2[46]=0; boton2[47]=1;
salondonog 0:b577167f506e 38
salondonog 0:b577167f506e 39 boton3[0]=0; boton3[1]=1; boton3[2]=0; boton3[3]=0; boton3[4]=0; boton3[5]=0; boton3[6]=0; boton3[7]=0; boton3[8]=0;
salondonog 0:b577167f506e 40 boton3[9]=0; boton3[10]=0; boton3[11]=0; boton3[12]=0; boton3[13]=1; boton3[14]=0; boton3[15]=0; boton3[16]=0; boton3[17]=0;
salondonog 0:b577167f506e 41 boton3[18]=0; boton3[19]=0; boton3[20]=0; boton3[21]=1; boton3[22]=0; boton3[23]=1; boton3[24]=0; boton3[25]=0; boton3[26]=1;
salondonog 0:b577167f506e 42 boton3[27]=1; boton3[28]=1; boton3[29]=0; boton3[30]=0; boton3[31]=0; boton3[32]=0; boton3[33]=1; boton3[34]=0; boton3[35]=0;
salondonog 0:b577167f506e 43 boton3[36]=1; boton3[37]=0; boton3[38]=0; boton3[39]=0; boton3[40]=0; boton3[41]=1; boton3[42]=1; boton3[43]=1; boton3[44]=0;
salondonog 0:b577167f506e 44 boton3[45]=1; boton3[46]=0; boton3[47]=1;
salondonog 0:b577167f506e 45 }
salondonog 0:b577167f506e 46
salondonog 0:b577167f506e 47 int main(){
salondonog 0:b577167f506e 48 conf_botones();
salondonog 0:b577167f506e 49 led2_B=1;
salondonog 0:b577167f506e 50 led2_G=1;
salondonog 0:b577167f506e 51 led2_R=1;
salondonog 0:b577167f506e 52
salondonog 0:b577167f506e 53 while(1){
salondonog 0:b577167f506e 54 ini1: header=0;
salondonog 0:b577167f506e 55 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo
salondonog 0:b577167f506e 56 if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20%
salondonog 0:b577167f506e 57 else goto ini1;
salondonog 0:b577167f506e 58
salondonog 0:b577167f506e 59 seguir:
salondonog 0:b577167f506e 60 //leo los datos de la trama y se meten a un arreglo
salondonog 0:b577167f506e 61 wait_us(1650/2);
salondonog 0:b577167f506e 62 for(i=0;i<(num_bits);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
salondonog 0:b577167f506e 63 dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control
salondonog 0:b577167f506e 64 num[i]=dato;
salondonog 0:b577167f506e 65 wait_us(550/2);
salondonog 0:b577167f506e 66 }
salondonog 0:b577167f506e 67 wait(0.5); //espero un poquito antes de leer todo el arreglo y ponerlo en pantalla
salondonog 0:b577167f506e 68 pc.printf(",%d",header);
salondonog 0:b577167f506e 69 for(i=0;i<(num_bits);++i){
salondonog 0:b577167f506e 70 pc.printf(",%d",num[i]);
salondonog 0:b577167f506e 71 }
salondonog 0:b577167f506e 72 wait(0.1); //espero e imprimo en binario
salondonog 0:b577167f506e 73 pc.printf("\n\n");
salondonog 0:b577167f506e 74 for(i=0;i<(num_bits);++i){
salondonog 0:b577167f506e 75 if(num[i] > ((T_alto+T_bajo)/2)){
salondonog 0:b577167f506e 76 arreglo[i]=1;
salondonog 0:b577167f506e 77 pc.printf("%d",arreglo[i]);
salondonog 0:b577167f506e 78 }
salondonog 0:b577167f506e 79 else{
salondonog 0:b577167f506e 80 arreglo[i]=0;
salondonog 0:b577167f506e 81 pc.printf("%d",arreglo[i]);
salondonog 0:b577167f506e 82 }
salondonog 0:b577167f506e 83 }
salondonog 0:b577167f506e 84
salondonog 0:b577167f506e 85 for(i=0;i<(num_bits);++i){
salondonog 0:b577167f506e 86 if(arreglo[i]==boton1[i]){
salondonog 0:b577167f506e 87 n++;
salondonog 0:b577167f506e 88 continue;
salondonog 0:b577167f506e 89 }
salondonog 0:b577167f506e 90 else{
salondonog 0:b577167f506e 91 n=0;
salondonog 0:b577167f506e 92 break;
salondonog 0:b577167f506e 93 }
salondonog 0:b577167f506e 94 }
salondonog 0:b577167f506e 95 pc.printf("\n %d",n);
salondonog 0:b577167f506e 96 if(n==48){
salondonog 0:b577167f506e 97 n=0;
salondonog 0:b577167f506e 98 led2_R=!led2_R;
salondonog 0:b577167f506e 99 goto ini1;
salondonog 0:b577167f506e 100 }
salondonog 0:b577167f506e 101
salondonog 0:b577167f506e 102 for(i=0;i<(num_bits);++i){
salondonog 0:b577167f506e 103 if(arreglo[i]==boton2[i]){
salondonog 0:b577167f506e 104 n++;
salondonog 0:b577167f506e 105 continue;
salondonog 0:b577167f506e 106 }
salondonog 0:b577167f506e 107 else{
salondonog 0:b577167f506e 108 n=0;
salondonog 0:b577167f506e 109 break;
salondonog 0:b577167f506e 110 }
salondonog 0:b577167f506e 111 }
salondonog 0:b577167f506e 112 pc.printf("\n %d",n);
salondonog 0:b577167f506e 113 if(n==48){
salondonog 0:b577167f506e 114 n=0;
salondonog 0:b577167f506e 115 led2_G=!led2_G;
salondonog 0:b577167f506e 116 goto ini1;
salondonog 0:b577167f506e 117 }
salondonog 0:b577167f506e 118 for(i=0;i<(num_bits);++i){
salondonog 0:b577167f506e 119 if(arreglo[i]==boton3[i]){
salondonog 0:b577167f506e 120 n++;
salondonog 0:b577167f506e 121 continue;
salondonog 0:b577167f506e 122 }
salondonog 0:b577167f506e 123 else{
salondonog 0:b577167f506e 124 n=0;
salondonog 0:b577167f506e 125 break;
salondonog 0:b577167f506e 126 }
salondonog 0:b577167f506e 127 }
salondonog 0:b577167f506e 128 pc.printf("\n %d",n);
salondonog 0:b577167f506e 129 if(n==48){
salondonog 0:b577167f506e 130 n=0;
salondonog 0:b577167f506e 131 led2_B=!led2_B;
salondonog 0:b577167f506e 132 goto ini1;
salondonog 0:b577167f506e 133 }
salondonog 0:b577167f506e 134 }
salondonog 0:b577167f506e 135 }