Gustavo Ramirez / Mbed 2 deprecated Sanitario_IRDA

Dependencies:   Pulse1 mbed

Fork of irda_Sony by Gustavo Ramirez

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <Pulse1.h>
00003 #include "stdio.h" 
00004 //control remoto sony disparo camara
00005 //puede convertir la trama en un entero
00006 //para cualquier tecla
00007 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
00008 Serial pc(USBTX, USBRX);
00009 DigitalOut led(LED1);
00010 DigitalOut dir(PTA1);
00011 DigitalOut breake(PTA2);
00012 DigitalOut led2(LED2);
00013 int header =0; //tiempo de cabecera pulso abajo
00014 const int head_H = 2976; //+10% medida con osciloscopio en microsegundos
00015 const int head_L = 1984;//-10%  medida con osciloscopio
00016 int i=0, bin, potencia;
00017 const int T_alto=1200;//ponga su tiempo de la prueba
00018 const int T_bajo=639;//ponga su tiempo de la prueba
00019 const int num_bits = 20;//ponga su numero de bits
00020 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
00021 int dato; // tiempo de cada dato que se lee
00022 int numero;
00023 int binM[20];
00024 int bin_max[20];
00025 Serial GSM(PTE0,PTE1);  //puertos del FRDM para el modem
00026 //GSM.printf("AT+CMGL=0\n\r"); 
00027 
00028 int main(){
00029 GSM.baud(9600);
00030 GSM.format(8,Serial::None,1);     
00031 breake=0;
00032 dir=0;
00033 wait(4);  
00034 breake=1;  
00035 while(1){
00036 ini1: fflush( stdin );
00037       header=0;
00038       led2=1;
00039       led=1;
00040       header = irda.read_low_us();    //funcion para leer un pulso de caida o bajo en header
00041       if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20%
00042       else goto ini1;
00043       
00044 seguir:
00045        //leo los datos de la trama y se meten a un arreglo
00046       wait_us(40);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 
00047       led2=1;
00048       for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
00049       dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control
00050       num[i]=dato;
00051       wait_us(400);   
00052       }
00053       wait(0.5); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla 
00054       //pc.printf(",%d",header);
00055       for(i=0;i<(num_bits-1);++i){  
00056       //pc.printf(",%d",num[i]);
00057       }
00058       wait(0.1);  //espero e imprimo en binario 
00059       //pc.printf("\n\n");
00060       for(i=0;i<(num_bits-1);++i){  
00061        if(num[i] > ((T_alto+T_bajo)/2)){
00062         bin_max[i]=1;
00063         }
00064        else{
00065         bin_max[i]=0;
00066           }
00067        
00068       }   
00069       binM[0]=1;
00070       for(i=1;i<(num_bits-1);++i){   
00071        binM[i]=binM[i-1]*2;
00072        
00073        }
00074      numero=0;   
00075      for(i=0;i<(num_bits-1);++i){  
00076      
00077      numero=numero+(binM[i]*bin_max[i]);
00078              
00079       }
00080       pc.printf("numero=%d",numero);
00081       if (numero==466221){
00082           led2=0;
00083           wait(1);
00084           led2=1;
00085           GSM.printf("N1\r\n");
00086           wait(1);
00087           GSM.printf("W230\r\n");
00088           wait(1);
00089           GSM.printf("L2\r\n");
00090           wait(1);          
00091           breake=0;
00092           dir=1;//abrir
00093           wait(4);//esperar que abra
00094           breake=1;//parar
00095           GSM.printf("S se inicia llenado del tanque\r\n"); 
00096           wait(70);//espera que llene
00097           dir=0;//CERRAR
00098           breake=0;
00099           wait(4);//esperar que cierre
00100           breake=1;//parar
00101           GSM.printf("Sel tanque esta lleno\r\n");           
00102           wait(3);
00103           GSM.printf("Spuede vaciar el sanitario\r\n");  
00104           wait(3);         
00105           GSM.printf("Sno olvide\r\n");  
00106           wait(4);
00107           GSM.printf("Srecuerde que JA JA JA JA JA\r\n");  
00108           wait(2);         
00109           wait(2);         
00110           goto ini1;
00111           }
00112       if (numero==466231){
00113           led=0;
00114           wait(2);
00115           led=1;
00116           goto ini1;
00117           }    
00118       }
00119       }