Programa para llenar un tanque de una cisterna por medio de un control de cámara sony. el sistema puede emitir sonidos por medio de un módulo de voz de Parallax EMIC.

Dependencies:   Pulse1 mbed

Fork of Sanitario_IRDA by Gustavo Ramirez

Committer:
tony63
Date:
Tue Apr 26 08:58:19 2016 +0000
Revision:
6:8cc9f4849678
Parent:
5:3036b626379b
Child:
7:79b0dc5d537e
correccion

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 //control remoto sony disparo camara
tony63 4:150bc6a5f5b4 5 //puede convertir la trama en un entero
tony63 4:150bc6a5f5b4 6 //para cualquier tecla
tony63 2:6a15ab0305c8 7 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
tony63 0:74d57f8ae247 8 Serial pc(USBTX, USBRX);
tony63 0:74d57f8ae247 9 DigitalOut led(LED1);
tony63 5:3036b626379b 10 DigitalOut dir(PTA1);
tony63 5:3036b626379b 11 DigitalOut breake(PTA2);
tony63 2:6a15ab0305c8 12 DigitalOut led2(LED2);
tony63 2:6a15ab0305c8 13 int header =0; //tiempo de cabecera pulso abajo
tony63 4:150bc6a5f5b4 14 const int head_H = 2976; //+10% medida con osciloscopio en microsegundos
tony63 4:150bc6a5f5b4 15 const int head_L = 1984;//-10% medida con osciloscopio
tony63 4:150bc6a5f5b4 16 int i=0, bin, potencia;
tony63 4:150bc6a5f5b4 17 const int T_alto=1200;//ponga su tiempo de la prueba
tony63 4:150bc6a5f5b4 18 const int T_bajo=639;//ponga su tiempo de la prueba
tony63 4:150bc6a5f5b4 19 const int num_bits = 20;//ponga su numero de bits
tony63 2:6a15ab0305c8 20 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
tony63 2:6a15ab0305c8 21 int dato; // tiempo de cada dato que se lee
tony63 4:150bc6a5f5b4 22 int numero;
tony63 4:150bc6a5f5b4 23 int binM[20];
tony63 4:150bc6a5f5b4 24 int bin_max[20];
tony63 5:3036b626379b 25 Serial GSM(PTE0,PTE1); //puertos del FRDM para el modem
tony63 5:3036b626379b 26 //GSM.printf("AT+CMGL=0\n\r");
tony63 4:150bc6a5f5b4 27
tony63 0:74d57f8ae247 28 int main(){
tony63 5:3036b626379b 29 GSM.baud(9600);
tony63 5:3036b626379b 30 GSM.format(8,Serial::None,1);
tony63 5:3036b626379b 31 breake=0;
tony63 5:3036b626379b 32 dir=0;
tony63 5:3036b626379b 33 wait(4);
tony63 5:3036b626379b 34 breake=1;
tony63 0:74d57f8ae247 35 while(1){
tony63 3:82bebaf2a06a 36 ini1: fflush( stdin );
tony63 3:82bebaf2a06a 37 header=0;
tony63 2:6a15ab0305c8 38 led2=1;
tony63 0:74d57f8ae247 39 led=1;
tony63 3:82bebaf2a06a 40 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header
tony63 2:6a15ab0305c8 41 if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20%
tony63 2:6a15ab0305c8 42 else goto ini1;
tony63 0:74d57f8ae247 43
tony63 2:6a15ab0305c8 44 seguir:
tony63 2:6a15ab0305c8 45 //leo los datos de la trama y se meten a un arreglo
tony63 5:3036b626379b 46 wait_us(40);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO
tony63 4:150bc6a5f5b4 47 led2=1;
tony63 2:6a15ab0305c8 48 for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
tony63 4:150bc6a5f5b4 49 dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control
tony63 2:6a15ab0305c8 50 num[i]=dato;
tony63 4:150bc6a5f5b4 51 wait_us(400);
tony63 2:6a15ab0305c8 52 }
tony63 3:82bebaf2a06a 53 wait(0.5); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla
tony63 4:150bc6a5f5b4 54 //pc.printf(",%d",header);
tony63 2:6a15ab0305c8 55 for(i=0;i<(num_bits-1);++i){
tony63 4:150bc6a5f5b4 56 //pc.printf(",%d",num[i]);
tony63 2:6a15ab0305c8 57 }
tony63 2:6a15ab0305c8 58 wait(0.1); //espero e imprimo en binario
tony63 4:150bc6a5f5b4 59 //pc.printf("\n\n");
tony63 2:6a15ab0305c8 60 for(i=0;i<(num_bits-1);++i){
tony63 4:150bc6a5f5b4 61 if(num[i] > ((T_alto+T_bajo)/2)){
tony63 4:150bc6a5f5b4 62 bin_max[i]=1;
tony63 4:150bc6a5f5b4 63 }
tony63 4:150bc6a5f5b4 64 else{
tony63 4:150bc6a5f5b4 65 bin_max[i]=0;
tony63 4:150bc6a5f5b4 66 }
tony63 4:150bc6a5f5b4 67
tony63 4:150bc6a5f5b4 68 }
tony63 4:150bc6a5f5b4 69 binM[0]=1;
tony63 4:150bc6a5f5b4 70 for(i=1;i<(num_bits-1);++i){
tony63 4:150bc6a5f5b4 71 binM[i]=binM[i-1]*2;
tony63 4:150bc6a5f5b4 72
tony63 4:150bc6a5f5b4 73 }
tony63 4:150bc6a5f5b4 74 numero=0;
tony63 4:150bc6a5f5b4 75 for(i=0;i<(num_bits-1);++i){
tony63 4:150bc6a5f5b4 76
tony63 4:150bc6a5f5b4 77 numero=numero+(binM[i]*bin_max[i]);
tony63 4:150bc6a5f5b4 78
tony63 2:6a15ab0305c8 79 }
tony63 4:150bc6a5f5b4 80 pc.printf("numero=%d",numero);
tony63 4:150bc6a5f5b4 81 if (numero==466221){
tony63 4:150bc6a5f5b4 82 led2=0;
tony63 5:3036b626379b 83 wait(1);
tony63 5:3036b626379b 84 led2=1;
tony63 5:3036b626379b 85 GSM.printf("N1\r\n");
tony63 5:3036b626379b 86 wait(1);
tony63 5:3036b626379b 87 GSM.printf("W230\r\n");
tony63 5:3036b626379b 88 wait(1);
tony63 5:3036b626379b 89 GSM.printf("L2\r\n");
tony63 5:3036b626379b 90 wait(1);
tony63 5:3036b626379b 91 breake=0;
tony63 5:3036b626379b 92 dir=1;//abrir
tony63 5:3036b626379b 93 wait(4);//esperar que abra
tony63 5:3036b626379b 94 breake=1;//parar
tony63 5:3036b626379b 95 GSM.printf("S se inicia llenado del tanque\r\n");
tony63 5:3036b626379b 96 wait(70);//espera que llene
tony63 5:3036b626379b 97 dir=0;//CERRAR
tony63 5:3036b626379b 98 breake=0;
tony63 5:3036b626379b 99 wait(4);//esperar que cierre
tony63 5:3036b626379b 100 breake=1;//parar
tony63 5:3036b626379b 101 GSM.printf("Sel tanque esta lleno\r\n");
tony63 5:3036b626379b 102 wait(3);
tony63 5:3036b626379b 103 GSM.printf("Spuede vaciar el sanitario\r\n");
tony63 5:3036b626379b 104 wait(3);
tony63 6:8cc9f4849678 105 GSM.printf("Sno olvide\r\n");
tony63 4:150bc6a5f5b4 106 wait(4);
tony63 6:8cc9f4849678 107 GSM.printf("Srecuerde que JA JA JA JA JA\r\n");
tony63 5:3036b626379b 108 wait(2);
tony63 5:3036b626379b 109 wait(2);
tony63 4:150bc6a5f5b4 110 goto ini1;
tony63 4:150bc6a5f5b4 111 }
tony63 4:150bc6a5f5b4 112 if (numero==466231){
tony63 4:150bc6a5f5b4 113 led=0;
tony63 5:3036b626379b 114 wait(2);
tony63 4:150bc6a5f5b4 115 led=1;
tony63 4:150bc6a5f5b4 116 goto ini1;
tony63 4:150bc6a5f5b4 117 }
tony63 2:6a15ab0305c8 118 }
tony63 2:6a15ab0305c8 119 }