Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of irda_V_aula by
Diff: main.cpp
- Revision:
- 2:6a15ab0305c8
- Parent:
- 0:74d57f8ae247
- Child:
- 3:82bebaf2a06a
--- a/main.cpp Thu Nov 07 03:37:01 2013 +0000
+++ b/main.cpp Fri Nov 08 07:40:04 2013 +0000
@@ -1,18 +1,48 @@
#include "mbed.h"
#include <Pulse1.h>
-PulseInOut irda(PTD5);
+PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
Serial pc(USBTX, USBRX);
DigitalOut led(LED1);
-int tiempo;
+DigitalOut led2(LED2);
+int header =0; //tiempo de cabecera pulso abajo
+const int head_H = 9100; //+20% medida con osciloscopio en microsegundos
+const int head_L = 8500;//-20% medida con osciloscopio
+int i=0;
+const int T_alto=1680;//ponga su tiempo de la prueba
+const int T_bajo=526;//ponga su tiempo de la prueba
+const int num_bits = 32;//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(){
while(1){
-tiempo = irda.read_high_us();
+ini1: header=0;
+ led2=1;
led=1;
- pc.printf("Header bajo dura %d us\n", tiempo);
- wait(0.3);
- led=0;
+ 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;
- }
- }
\ No newline at end of file
+seguir:
+ //leo los datos de la trama y se meten a un arreglo
+ wait_us(5000);
+ led2=0;
+ for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
+ dato = irda.read_high_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
