preder led con un sessor infrarojo

Dependencies:   Pulse1 mbed

Files at this revision

API Documentation at this revision

Comitter:
laura608
Date:
Wed Nov 20 14:44:32 2013 +0000
Commit message:
irda;

Changed in this revision

Pulse1.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pulse1.lib	Wed Nov 20 14:44:32 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tony63/code/Pulse1/#48651f86a80c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 20 14:44:32 2013 +0000
@@ -0,0 +1,55 @@
+#include "mbed.h"
+#include <Pulse1.h>
+
+PulseInOut irda(PTD5);
+Serial pc(USBTX, USBRX);
+DigitalOut l0(LED1);
+DigitalOut l1(LED2);
+DigitalOut l2(LED3);
+
+int header =0;
+const int head_H = 2964; //+20% medida con osciloscopio en microsegundos
+const int head_L = 1976;//-20%  medida con osciloscopio
+int i=0;
+const int T_alto=1200;//ponga su tiempo de la prueba
+const int T_bajo=600;//ponga su tiempo de la prueba
+const int num_bits = 21;//ponga su numero de bits
+int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
+int dato; // tiempo de cada dato que se lee
+  
+int main(){
+    l0=l1=l2=1;
+    while(1){
+        ini1: header=0;
+        l1=l0=l2=1;
+        header = irda.read_low_us();    //funcion para leer un pulso de caida o bajo
+        if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20%
+        else goto ini1;
+      
+        seguir:
+        wait_us(300);
+        l0=0;
+        l1=0;
+        l2=0;
+        
+        for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
+            dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control
+            num[i]=dato;
+            wait_us(300);   
+        }
+        
+        wait(0.5); //espero un poquito antes de leer todo el arreglo y ponerlo en pantalla 
+        pc.printf(",%d",header);
+        
+        for(i=0;i<(num_bits-1);++i){  
+            pc.printf(",%d",num[i]);
+        }
+        
+        wait(0.1);  //espero e imprimo en binario 
+        pc.printf("\n\n");
+        for(i=0;i<(num_bits-1);++i){  
+            if(num[i] > ((T_alto+T_bajo)/2)) pc.printf("1");
+            else pc.printf("0");
+        }
+      }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 20 14:44:32 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file