es una versión mejorada que no requiere suiche y da mas informacion
Fork of CAPTURAS_IRDA by
main.cpp@0:86c0c1652dd4, 2017-03-18 (annotated)
- Committer:
- tony63
- Date:
- Sat Mar 18 00:59:20 2017 +0000
- Revision:
- 0:86c0c1652dd4
- Child:
- 1:69f833c768c8
CAPTURAS DE C?DIGOS IRDA SIN OSCILOSCOPIO, MIDE LA CANTIDAD DE ESPACIOS EN MODO NORMAL LA DURACI?N Y EL PROMEDIO DE ELLOS. CON LA AYUDA DE PULSAR BAJO UN BOT?N DEVUELVE EL CODIGO COMPLETO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:86c0c1652dd4 | 1 | #include "mbed.h" |
tony63 | 0:86c0c1652dd4 | 2 | #include <Pulse1.h> |
tony63 | 0:86c0c1652dd4 | 3 | PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo |
tony63 | 0:86c0c1652dd4 | 4 | |
tony63 | 0:86c0c1652dd4 | 5 | Serial pc(USBTX, USBRX); |
tony63 | 0:86c0c1652dd4 | 6 | DigitalOut led(LED1); |
tony63 | 0:86c0c1652dd4 | 7 | DigitalOut led2(LED2); |
tony63 | 0:86c0c1652dd4 | 8 | DigitalIn mode(PTD0); |
tony63 | 0:86c0c1652dd4 | 9 | int numN[70];//cadena para almacenar todos los tiempos que conforman los bits de datos |
tony63 | 0:86c0c1652dd4 | 10 | int numP[70];//cadena para almacenar todos los tiempos que conforman los bits de datos |
tony63 | 0:86c0c1652dd4 | 11 | int dato; // tiempo de cada dato que se lee |
tony63 | 0:86c0c1652dd4 | 12 | int pul_low; |
tony63 | 0:86c0c1652dd4 | 13 | int i,j,k,header,proL,proH; |
tony63 | 0:86c0c1652dd4 | 14 | int r; |
tony63 | 0:86c0c1652dd4 | 15 | int main(){ |
tony63 | 0:86c0c1652dd4 | 16 | Timer t; |
tony63 | 0:86c0c1652dd4 | 17 | fflush( stdin ); |
tony63 | 0:86c0c1652dd4 | 18 | lop1: header = irda.read_low_us(); |
tony63 | 0:86c0c1652dd4 | 19 | if(header>8000) goto seguir; |
tony63 | 0:86c0c1652dd4 | 20 | goto lop1; |
tony63 | 0:86c0c1652dd4 | 21 | seguir: |
tony63 | 0:86c0c1652dd4 | 22 | for(i=0;i<35;++i){ |
tony63 | 0:86c0c1652dd4 | 23 | if(mode){ |
tony63 | 0:86c0c1652dd4 | 24 | numN[i] = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header |
tony63 | 0:86c0c1652dd4 | 25 | } |
tony63 | 0:86c0c1652dd4 | 26 | if(!mode){ |
tony63 | 0:86c0c1652dd4 | 27 | numP[i] = irda.read_high_us(); //funcion para leer un pulso de caida o bajo en header |
tony63 | 0:86c0c1652dd4 | 28 | } |
tony63 | 0:86c0c1652dd4 | 29 | //funcion para leer un pulso de caida o bajo en header |
tony63 | 0:86c0c1652dd4 | 30 | } |
tony63 | 0:86c0c1652dd4 | 31 | |
tony63 | 0:86c0c1652dd4 | 32 | pc.printf("Header=%d \n",header," uS"); |
tony63 | 0:86c0c1652dd4 | 33 | for(i=0;i<36;++i){ |
tony63 | 0:86c0c1652dd4 | 34 | pc.printf(",%d, %d, %d \n",numN[i],i,numP[i]); |
tony63 | 0:86c0c1652dd4 | 35 | |
tony63 | 0:86c0c1652dd4 | 36 | if(numN[i]>8000){ |
tony63 | 0:86c0c1652dd4 | 37 | pc.printf("\n"); |
tony63 | 0:86c0c1652dd4 | 38 | pc.printf("espacios=%d\n",i); |
tony63 | 0:86c0c1652dd4 | 39 | k=i; |
tony63 | 0:86c0c1652dd4 | 40 | proL=0; |
tony63 | 0:86c0c1652dd4 | 41 | for(i=0;i<k;++i){ |
tony63 | 0:86c0c1652dd4 | 42 | proL=proL+numN[i]; |
tony63 | 0:86c0c1652dd4 | 43 | } |
tony63 | 0:86c0c1652dd4 | 44 | proL=proL/k; |
tony63 | 0:86c0c1652dd4 | 45 | pc.printf("promedio_E=%d\n",proL); |
tony63 | 0:86c0c1652dd4 | 46 | wait(3); |
tony63 | 0:86c0c1652dd4 | 47 | pc.printf("\n"); |
tony63 | 0:86c0c1652dd4 | 48 | |
tony63 | 0:86c0c1652dd4 | 49 | if(!mode){ |
tony63 | 0:86c0c1652dd4 | 50 | for(i=0;i<k-1;++i){ |
tony63 | 0:86c0c1652dd4 | 51 | if(numP[i]>(2*proL)){ |
tony63 | 0:86c0c1652dd4 | 52 | pc.printf("1"); |
tony63 | 0:86c0c1652dd4 | 53 | } |
tony63 | 0:86c0c1652dd4 | 54 | if(numP[i]<(2*proL)){ |
tony63 | 0:86c0c1652dd4 | 55 | pc.printf("0"); |
tony63 | 0:86c0c1652dd4 | 56 | } |
tony63 | 0:86c0c1652dd4 | 57 | } |
tony63 | 0:86c0c1652dd4 | 58 | } |
tony63 | 0:86c0c1652dd4 | 59 | |
tony63 | 0:86c0c1652dd4 | 60 | goto lop1; |
tony63 | 0:86c0c1652dd4 | 61 | |
tony63 | 0:86c0c1652dd4 | 62 | } |
tony63 | 0:86c0c1652dd4 | 63 | } |
tony63 | 0:86c0c1652dd4 | 64 | } |
tony63 | 0:86c0c1652dd4 | 65 | |
tony63 | 0:86c0c1652dd4 | 66 |