/control remoto sony disparo camara //puede convertir la trama en un entero //para cualquier tecla

Dependencies:   Pulse1 mbed

Fork of irda_V_aula by Gustavo Ramirez

Committer:
tony63
Date:
Tue Apr 26 04:23:42 2016 +0000
Revision:
4:150bc6a5f5b4
Parent:
3:82bebaf2a06a
/control remoto sony disparo camara; //puede convertir la trama en un entero y facilitar la comparacion; //para cualquier tecla

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tony63 0:74d57f8ae247 1 #include "mbed.h"
tony63 0:74d57f8ae247 2 #include <Pulse1.h>
tony63 4:150bc6a5f5b4 3 #include "stdio.h"
tony63 4:150bc6a5f5b4 4 #include "math.h"
tony63 4:150bc6a5f5b4 5 //control remoto sony disparo camara
tony63 4:150bc6a5f5b4 6 //puede convertir la trama en un entero
tony63 4:150bc6a5f5b4 7 //para cualquier tecla
tony63 2:6a15ab0305c8 8 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
tony63 0:74d57f8ae247 9 Serial pc(USBTX, USBRX);
tony63 0:74d57f8ae247 10 DigitalOut led(LED1);
tony63 2:6a15ab0305c8 11 DigitalOut led2(LED2);
tony63 2:6a15ab0305c8 12 int header =0; //tiempo de cabecera pulso abajo
tony63 4:150bc6a5f5b4 13 const int head_H = 2976; //+10% medida con osciloscopio en microsegundos
tony63 4:150bc6a5f5b4 14 const int head_L = 1984;//-10% medida con osciloscopio
tony63 4:150bc6a5f5b4 15 int i=0, bin, potencia;
tony63 4:150bc6a5f5b4 16 const int T_alto=1200;//ponga su tiempo de la prueba
tony63 4:150bc6a5f5b4 17 const int T_bajo=639;//ponga su tiempo de la prueba
tony63 4:150bc6a5f5b4 18 const int num_bits = 20;//ponga su numero de bits
tony63 2:6a15ab0305c8 19 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
tony63 2:6a15ab0305c8 20 int dato; // tiempo de cada dato que se lee
tony63 4:150bc6a5f5b4 21 int numero;
tony63 4:150bc6a5f5b4 22 int binM[20];
tony63 4:150bc6a5f5b4 23 int bin_max[20];
tony63 4:150bc6a5f5b4 24
tony63 4:150bc6a5f5b4 25
tony63 4:150bc6a5f5b4 26
tony63 0:74d57f8ae247 27 int main(){
tony63 0:74d57f8ae247 28 while(1){
tony63 3:82bebaf2a06a 29 ini1: fflush( stdin );
tony63 3:82bebaf2a06a 30 header=0;
tony63 2:6a15ab0305c8 31 led2=1;
tony63 0:74d57f8ae247 32 led=1;
tony63 3:82bebaf2a06a 33 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header
tony63 2:6a15ab0305c8 34 if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20%
tony63 2:6a15ab0305c8 35 else goto ini1;
tony63 0:74d57f8ae247 36
tony63 2:6a15ab0305c8 37 seguir:
tony63 2:6a15ab0305c8 38 //leo los datos de la trama y se meten a un arreglo
tony63 4:150bc6a5f5b4 39 wait_us(400);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO
tony63 4:150bc6a5f5b4 40 led2=1;
tony63 2:6a15ab0305c8 41 for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
tony63 4:150bc6a5f5b4 42 dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control
tony63 2:6a15ab0305c8 43 num[i]=dato;
tony63 4:150bc6a5f5b4 44 wait_us(400);
tony63 2:6a15ab0305c8 45 }
tony63 3:82bebaf2a06a 46 wait(0.5); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla
tony63 4:150bc6a5f5b4 47 //pc.printf(",%d",header);
tony63 2:6a15ab0305c8 48 for(i=0;i<(num_bits-1);++i){
tony63 4:150bc6a5f5b4 49 //pc.printf(",%d",num[i]);
tony63 2:6a15ab0305c8 50 }
tony63 2:6a15ab0305c8 51 wait(0.1); //espero e imprimo en binario
tony63 4:150bc6a5f5b4 52 //pc.printf("\n\n");
tony63 2:6a15ab0305c8 53 for(i=0;i<(num_bits-1);++i){
tony63 4:150bc6a5f5b4 54 if(num[i] > ((T_alto+T_bajo)/2)){
tony63 4:150bc6a5f5b4 55 bin_max[i]=1;
tony63 4:150bc6a5f5b4 56 }
tony63 4:150bc6a5f5b4 57 else{
tony63 4:150bc6a5f5b4 58 bin_max[i]=0;
tony63 4:150bc6a5f5b4 59 }
tony63 4:150bc6a5f5b4 60
tony63 4:150bc6a5f5b4 61 }
tony63 4:150bc6a5f5b4 62 binM[0]=1;
tony63 4:150bc6a5f5b4 63 for(i=1;i<(num_bits-1);++i){
tony63 4:150bc6a5f5b4 64 binM[i]=binM[i-1]*2;
tony63 4:150bc6a5f5b4 65
tony63 4:150bc6a5f5b4 66 }
tony63 4:150bc6a5f5b4 67 numero=0;
tony63 4:150bc6a5f5b4 68 for(i=0;i<(num_bits-1);++i){
tony63 4:150bc6a5f5b4 69
tony63 4:150bc6a5f5b4 70 numero=numero+(binM[i]*bin_max[i]);
tony63 4:150bc6a5f5b4 71
tony63 2:6a15ab0305c8 72 }
tony63 4:150bc6a5f5b4 73 pc.printf("numero=%d",numero);
tony63 4:150bc6a5f5b4 74 if (numero==466221){
tony63 4:150bc6a5f5b4 75 led2=0;
tony63 4:150bc6a5f5b4 76 wait(4);
tony63 4:150bc6a5f5b4 77 led2=1;
tony63 4:150bc6a5f5b4 78 goto ini1;
tony63 4:150bc6a5f5b4 79 }
tony63 4:150bc6a5f5b4 80 if (numero==466231){
tony63 4:150bc6a5f5b4 81 led=0;
tony63 4:150bc6a5f5b4 82 wait(4);
tony63 4:150bc6a5f5b4 83 led=1;
tony63 4:150bc6a5f5b4 84 goto ini1;
tony63 4:150bc6a5f5b4 85 }
tony63 2:6a15ab0305c8 86 }
tony63 2:6a15ab0305c8 87 }