Sebastian Quintero Zapata
/
IRDA_Control_Sony
En este archivo se encuentra la tarea del control remoto (Sony) haciendo uso del IRDA
main.cpp@0:4c98a66f8458, 2015-11-23 (annotated)
- Committer:
- squinteroz
- Date:
- Mon Nov 23 03:16:01 2015 +0000
- Revision:
- 0:4c98a66f8458
En este archivo se encuentra la tarea del control remoto (Sony) haciendo uso del IRDA
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
squinteroz | 0:4c98a66f8458 | 1 | #include "mbed.h" |
squinteroz | 0:4c98a66f8458 | 2 | #include <Pulse1.h> |
squinteroz | 0:4c98a66f8458 | 3 | #include <string.h> |
squinteroz | 0:4c98a66f8458 | 4 | //control remoto videobeam aula |
squinteroz | 0:4c98a66f8458 | 5 | PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo |
squinteroz | 0:4c98a66f8458 | 6 | Serial pc(USBTX, USBRX); |
squinteroz | 0:4c98a66f8458 | 7 | PwmOut l0(PTD0); |
squinteroz | 0:4c98a66f8458 | 8 | DigitalOut l1(PTD2); |
squinteroz | 0:4c98a66f8458 | 9 | DigitalOut l2(LED2); |
squinteroz | 0:4c98a66f8458 | 10 | //PwmOut pwmLed(LED1); |
squinteroz | 0:4c98a66f8458 | 11 | |
squinteroz | 0:4c98a66f8458 | 12 | int header =0; |
squinteroz | 0:4c98a66f8458 | 13 | const int head_H = 2880; //+20% medida con osciloscopio en microsegundos |
squinteroz | 0:4c98a66f8458 | 14 | const int head_L = 1920;//-20% medida con osciloscopio |
squinteroz | 0:4c98a66f8458 | 15 | int i=0; |
squinteroz | 0:4c98a66f8458 | 16 | const int T_alto=567;//ponga su tiempo de la prueba |
squinteroz | 0:4c98a66f8458 | 17 | const int T_bajo=1170;//ponga su tiempo de la prueba |
squinteroz | 0:4c98a66f8458 | 18 | const int num_bits = 21;//ponga su numero de bits |
squinteroz | 0:4c98a66f8458 | 19 | int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos |
squinteroz | 0:4c98a66f8458 | 20 | int aux[21]; |
squinteroz | 0:4c98a66f8458 | 21 | int dato,prender,subir,bajar,k; // tiempo de cada dato que se lee; // tiempo de cada dato que se lee |
squinteroz | 0:4c98a66f8458 | 22 | |
squinteroz | 0:4c98a66f8458 | 23 | |
squinteroz | 0:4c98a66f8458 | 24 | int powerSONY[]= {0,1,0,0,1,1,0,0,1,0,1,1,1,0,0,1,0,0,1,0,1}; //Boton para prender y apagar |
squinteroz | 0:4c98a66f8458 | 25 | int subirDVD[] ={1,0,0,1,1,1,1,0,1,0,1,1,1,0,0,1,0,0,1,0,1}; //Boton para aumentar el PWM |
squinteroz | 0:4c98a66f8458 | 26 | int bajarDVD[]={0,1,0,1,1,1,1,0,1,0,1,1,1,0,0,1,0,0,1,0,1}; //Boton para disminuir el PWM |
squinteroz | 0:4c98a66f8458 | 27 | |
squinteroz | 0:4c98a66f8458 | 28 | int main(){ |
squinteroz | 0:4c98a66f8458 | 29 | //pwmLed=0; |
squinteroz | 0:4c98a66f8458 | 30 | |
squinteroz | 0:4c98a66f8458 | 31 | while(1){ |
squinteroz | 0:4c98a66f8458 | 32 | |
squinteroz | 0:4c98a66f8458 | 33 | ini1: |
squinteroz | 0:4c98a66f8458 | 34 | fflush( stdin ); |
squinteroz | 0:4c98a66f8458 | 35 | header=0; |
squinteroz | 0:4c98a66f8458 | 36 | //l1=1; |
squinteroz | 0:4c98a66f8458 | 37 | header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo |
squinteroz | 0:4c98a66f8458 | 38 | if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% |
squinteroz | 0:4c98a66f8458 | 39 | else goto ini1; |
squinteroz | 0:4c98a66f8458 | 40 | |
squinteroz | 0:4c98a66f8458 | 41 | seguir: |
squinteroz | 0:4c98a66f8458 | 42 | wait_us(333); |
squinteroz | 0:4c98a66f8458 | 43 | //l1=0; |
squinteroz | 0:4c98a66f8458 | 44 | for(i=0;i<=(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos |
squinteroz | 0:4c98a66f8458 | 45 | dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control |
squinteroz | 0:4c98a66f8458 | 46 | num[i]=dato; |
squinteroz | 0:4c98a66f8458 | 47 | wait_us(333); |
squinteroz | 0:4c98a66f8458 | 48 | } |
squinteroz | 0:4c98a66f8458 | 49 | |
squinteroz | 0:4c98a66f8458 | 50 | wait(0.5); //espero un poquito antes de leer todo el arreglo y ponerlo en pantalla |
squinteroz | 0:4c98a66f8458 | 51 | //pc.printf(",%d",header); |
squinteroz | 0:4c98a66f8458 | 52 | |
squinteroz | 0:4c98a66f8458 | 53 | for(i=0;i<=(num_bits-1);++i){ |
squinteroz | 0:4c98a66f8458 | 54 | // pc.printf(",%d",num[i]); |
squinteroz | 0:4c98a66f8458 | 55 | } |
squinteroz | 0:4c98a66f8458 | 56 | |
squinteroz | 0:4c98a66f8458 | 57 | wait(0.1); //espero |
squinteroz | 0:4c98a66f8458 | 58 | pc.printf("\n\n");//imprimo en binario |
squinteroz | 0:4c98a66f8458 | 59 | for(i=0;i<=(num_bits-1);++i){ |
squinteroz | 0:4c98a66f8458 | 60 | if(num[i] > ((T_alto+T_bajo)/2)){ |
squinteroz | 0:4c98a66f8458 | 61 | pc.printf("1"); |
squinteroz | 0:4c98a66f8458 | 62 | aux[i]=1; |
squinteroz | 0:4c98a66f8458 | 63 | } |
squinteroz | 0:4c98a66f8458 | 64 | else { |
squinteroz | 0:4c98a66f8458 | 65 | pc.printf("0"); |
squinteroz | 0:4c98a66f8458 | 66 | aux[i]=0; |
squinteroz | 0:4c98a66f8458 | 67 | } |
squinteroz | 0:4c98a66f8458 | 68 | } |
squinteroz | 0:4c98a66f8458 | 69 | |
squinteroz | 0:4c98a66f8458 | 70 | prender=0; |
squinteroz | 0:4c98a66f8458 | 71 | subir=0; |
squinteroz | 0:4c98a66f8458 | 72 | bajar=0; |
squinteroz | 0:4c98a66f8458 | 73 | |
squinteroz | 0:4c98a66f8458 | 74 | if(aux[0]==powerSONY[0]&&aux[1]==powerSONY[1]&&aux[2]==powerSONY[2]&&aux[3]==powerSONY[3]&&aux[4]==powerSONY[4]&&aux[5]==powerSONY[5]&&aux[6]==powerSONY[6]&&aux[7]==powerSONY[7]){ |
squinteroz | 0:4c98a66f8458 | 75 | //Se compara uno por uno de los 8 bits a comparar |
squinteroz | 0:4c98a66f8458 | 76 | prender=21; //Se asigna un valor a la variable de prender, se llamará despues |
squinteroz | 0:4c98a66f8458 | 77 | pc.printf("ON");//Muestra en pantalla que se prendió |
squinteroz | 0:4c98a66f8458 | 78 | } |
squinteroz | 0:4c98a66f8458 | 79 | if(aux[0]==subirDVD[0]&&aux[1]==subirDVD[1]&&aux[2]==subirDVD[2]&&aux[3]==subirDVD[3]&&aux[4]==subirDVD[4]&&aux[5]==subirDVD[5]&&aux[6]==subirDVD[6]&&aux[7]==subirDVD[7]){ |
squinteroz | 0:4c98a66f8458 | 80 | //Se compara uno por uno de los 8 bits a comparar |
squinteroz | 0:4c98a66f8458 | 81 | subir=21;//Se asigna un valor a la variable de subir, se llamará despues |
squinteroz | 0:4c98a66f8458 | 82 | pc.printf("UP");//Muestra en terminal, que esta aumentando el PWM |
squinteroz | 0:4c98a66f8458 | 83 | } |
squinteroz | 0:4c98a66f8458 | 84 | if(aux[0]==bajarDVD[0]&&aux[1]==bajarDVD[1]&&aux[2]==bajarDVD[2]&&aux[3]==bajarDVD[3]&&aux[4]==bajarDVD[4]&&aux[5]==bajarDVD[5]&&aux[6]==bajarDVD[6]&&aux[7]==bajarDVD[7]){ |
squinteroz | 0:4c98a66f8458 | 85 | //Se compara uno por uno de los 8 bits a comparar |
squinteroz | 0:4c98a66f8458 | 86 | bajar=21;//Se asigna un valor a la variable de bajar, se llamará despues |
squinteroz | 0:4c98a66f8458 | 87 | pc.printf("DOWN");//Muestra en terminal, que esta disminuyendo el PWM |
squinteroz | 0:4c98a66f8458 | 88 | } |
squinteroz | 0:4c98a66f8458 | 89 | |
squinteroz | 0:4c98a66f8458 | 90 | |
squinteroz | 0:4c98a66f8458 | 91 | if (l1==0 && prender==21){ |
squinteroz | 0:4c98a66f8458 | 92 | l1=1; |
squinteroz | 0:4c98a66f8458 | 93 | l0=1; |
squinteroz | 0:4c98a66f8458 | 94 | //Si se apreto el boton de prender y el sistema esta apagado, enciende, y visceversa |
squinteroz | 0:4c98a66f8458 | 95 | } |
squinteroz | 0:4c98a66f8458 | 96 | else if (l1==1 && prender==21){ |
squinteroz | 0:4c98a66f8458 | 97 | l1=0; |
squinteroz | 0:4c98a66f8458 | 98 | l0=0; |
squinteroz | 0:4c98a66f8458 | 99 | } |
squinteroz | 0:4c98a66f8458 | 100 | |
squinteroz | 0:4c98a66f8458 | 101 | if (subir==21 && l0<1){ |
squinteroz | 0:4c98a66f8458 | 102 | if (l0>=1) l0=1; |
squinteroz | 0:4c98a66f8458 | 103 | l0=l0+0.15; |
squinteroz | 0:4c98a66f8458 | 104 | //Si se apreto el boton de subir y el sistema aumenta el PWM. |
squinteroz | 0:4c98a66f8458 | 105 | } |
squinteroz | 0:4c98a66f8458 | 106 | |
squinteroz | 0:4c98a66f8458 | 107 | if (bajar==21 && 0<l0){ |
squinteroz | 0:4c98a66f8458 | 108 | if (l0<=0) l0=0; |
squinteroz | 0:4c98a66f8458 | 109 | l0=l0-0.15; |
squinteroz | 0:4c98a66f8458 | 110 | //Si se apreto el boton de bajar y el sistema disminuye el PWM. |
squinteroz | 0:4c98a66f8458 | 111 | } |
squinteroz | 0:4c98a66f8458 | 112 | } |
squinteroz | 0:4c98a66f8458 | 113 | } |