![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Programa para encedido de 3 Leds por medio de un control Sony oprimiendo las teclas 1,2 y 3
Control.cpp@1:e86784430f01, 2013-12-12 (annotated)
- Committer:
- leorestrepo93
- Date:
- Thu Dec 12 13:46:28 2013 +0000
- Revision:
- 1:e86784430f01
- Parent:
- main.cpp@0:ede132a1e72c
Infrarrojo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leorestrepo93 | 0:ede132a1e72c | 1 | #include "mbed.h" |
leorestrepo93 | 0:ede132a1e72c | 2 | #include <Pulse1.h> |
leorestrepo93 | 0:ede132a1e72c | 3 | |
leorestrepo93 | 0:ede132a1e72c | 4 | PulseInOut irda(PTD5); |
leorestrepo93 | 0:ede132a1e72c | 5 | Serial pc(USBTX, USBRX); |
leorestrepo93 | 0:ede132a1e72c | 6 | DigitalOut l0(LED1); |
leorestrepo93 | 0:ede132a1e72c | 7 | DigitalOut l1(LED2); |
leorestrepo93 | 0:ede132a1e72c | 8 | DigitalOut l2(LED3); |
leorestrepo93 | 0:ede132a1e72c | 9 | |
leorestrepo93 | 0:ede132a1e72c | 10 | int header =0; |
leorestrepo93 | 0:ede132a1e72c | 11 | const int head_H = 2964; //+20% medida con osciloscopio en microsegundos |
leorestrepo93 | 0:ede132a1e72c | 12 | const int head_L = 1976;//-20% medida con osciloscopio |
leorestrepo93 | 0:ede132a1e72c | 13 | int i=0; |
leorestrepo93 | 0:ede132a1e72c | 14 | const int T_alto=1200;//ponga su tiempo de la prueba |
leorestrepo93 | 0:ede132a1e72c | 15 | const int T_bajo=600;//ponga su tiempo de la prueba |
leorestrepo93 | 0:ede132a1e72c | 16 | const int num_bits = 21;//ponga su numero de bits |
leorestrepo93 | 0:ede132a1e72c | 17 | int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos |
leorestrepo93 | 0:ede132a1e72c | 18 | int dato; // tiempo de cada dato que se lee |
leorestrepo93 | 0:ede132a1e72c | 19 | int n1[20],n2[20],n3[20]; |
leorestrepo93 | 0:ede132a1e72c | 20 | |
leorestrepo93 | 0:ede132a1e72c | 21 | int main(){ |
leorestrepo93 | 0:ede132a1e72c | 22 | 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; |
leorestrepo93 | 0:ede132a1e72c | 23 | n1[8]=n1[10]=n1[11]=n1[12]=n1[15]=n1[18]=1; |
leorestrepo93 | 0:ede132a1e72c | 24 | 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; |
leorestrepo93 | 0:ede132a1e72c | 25 | n2[8]=n2[10]=n2[11]=n2[12]=n2[15]=n2[18]=n2[0]=1; |
leorestrepo93 | 0:ede132a1e72c | 26 | 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; |
leorestrepo93 | 0:ede132a1e72c | 27 | n3[8]=n3[10]=n3[11]=n3[12]=n3[15]=n3[18]=n3[1]=1; |
leorestrepo93 | 0:ede132a1e72c | 28 | int w,e,r; |
leorestrepo93 | 0:ede132a1e72c | 29 | w=e=r=0; |
leorestrepo93 | 0:ede132a1e72c | 30 | l0=l1=l2=1; |
leorestrepo93 | 0:ede132a1e72c | 31 | while(1){ |
leorestrepo93 | 0:ede132a1e72c | 32 | ini1: header=0; |
leorestrepo93 | 0:ede132a1e72c | 33 | header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo |
leorestrepo93 | 0:ede132a1e72c | 34 | if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% |
leorestrepo93 | 0:ede132a1e72c | 35 | else goto ini1; |
leorestrepo93 | 0:ede132a1e72c | 36 | |
leorestrepo93 | 0:ede132a1e72c | 37 | seguir: |
leorestrepo93 | 0:ede132a1e72c | 38 | wait_us(300); |
leorestrepo93 | 0:ede132a1e72c | 39 | |
leorestrepo93 | 0:ede132a1e72c | 40 | for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos |
leorestrepo93 | 0:ede132a1e72c | 41 | dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control |
leorestrepo93 | 0:ede132a1e72c | 42 | num[i]=dato; |
leorestrepo93 | 0:ede132a1e72c | 43 | wait_us(300); |
leorestrepo93 | 0:ede132a1e72c | 44 | } |
leorestrepo93 | 0:ede132a1e72c | 45 | |
leorestrepo93 | 0:ede132a1e72c | 46 | wait(0.5); //espero un poquito antes de leer todo el arreglo y ponerlo en pantalla |
leorestrepo93 | 0:ede132a1e72c | 47 | |
leorestrepo93 | 0:ede132a1e72c | 48 | for(i=0;i<(num_bits-1);++i){ |
leorestrepo93 | 0:ede132a1e72c | 49 | if(num[i] > ((T_alto+T_bajo)/2)) num[i]=1; |
leorestrepo93 | 0:ede132a1e72c | 50 | else num[i]=0; |
leorestrepo93 | 0:ede132a1e72c | 51 | } |
leorestrepo93 | 0:ede132a1e72c | 52 | for(i=0;i<(num_bits-1);++i){ |
leorestrepo93 | 0:ede132a1e72c | 53 | if(num[i]==n1[i])w++; |
leorestrepo93 | 0:ede132a1e72c | 54 | } |
leorestrepo93 | 0:ede132a1e72c | 55 | |
leorestrepo93 | 0:ede132a1e72c | 56 | if(w==20){ |
leorestrepo93 | 0:ede132a1e72c | 57 | l0=!l0; |
leorestrepo93 | 0:ede132a1e72c | 58 | } |
leorestrepo93 | 0:ede132a1e72c | 59 | for(i=0;i<(num_bits-1);++i){ |
leorestrepo93 | 0:ede132a1e72c | 60 | if(num[i]==n2[i])e++; |
leorestrepo93 | 0:ede132a1e72c | 61 | } |
leorestrepo93 | 0:ede132a1e72c | 62 | |
leorestrepo93 | 0:ede132a1e72c | 63 | if(e==20){ |
leorestrepo93 | 0:ede132a1e72c | 64 | l1=!l1; |
leorestrepo93 | 0:ede132a1e72c | 65 | } |
leorestrepo93 | 0:ede132a1e72c | 66 | for(i=0;i<(num_bits-1);++i){ |
leorestrepo93 | 0:ede132a1e72c | 67 | if(num[i]==n3[i])r++; |
leorestrepo93 | 0:ede132a1e72c | 68 | } |
leorestrepo93 | 0:ede132a1e72c | 69 | |
leorestrepo93 | 0:ede132a1e72c | 70 | if(r==20){ |
leorestrepo93 | 0:ede132a1e72c | 71 | l2=!l2; |
leorestrepo93 | 0:ede132a1e72c | 72 | } |
leorestrepo93 | 0:ede132a1e72c | 73 | w=e=r=0; |
leorestrepo93 | 0:ede132a1e72c | 74 | } |
leorestrepo93 | 0:ede132a1e72c | 75 | } |