por medio de un control remoto y tres de sus botones se enciende un led diferente con cada botón, se muestra el numero de bits, su código, tiempo de duración de la cabecera y tiempos de duración en unos y ceros.

Dependencies:   Pulse1 TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
lopjohn_26
Date:
Fri May 16 15:42:27 2014 +0000
Commit message:
control remoto y botones

Changed in this revision

Pulse1.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.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	Fri May 16 15:42:27 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tony63/code/Pulse1/#48651f86a80c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri May 16 15:42:27 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/javiernegrette/code/TextLCD/#419979c1e228
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 16 15:42:27 2014 +0000
@@ -0,0 +1,236 @@
+#include "mbed.h"
+#include <Pulse1.h>
+#include "TextLCD.h"
+
+//
+//JUAN ESTEBAN alcance a realizar algo más del codigo mientras estaba en el hospital, el codigo ademas de apagar y prender el led, 
+//muestra el codigo del boton y el numero de bits.
+
+//control remoto 
+PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
+Serial pc(USBTX, USBRX);
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); //Puertos LCD rs, e, d4, d5, d6, d7
+
+DigitalOut led3(LED3);
+DigitalOut led4(LED2);  // aqui se configuran las salidas donde a donde se conectan los leds
+DigitalOut led5(LED1);
+
+int header =0; //tiempo de cabecera pulso abajo
+const int head_H = 2860; //+10% medida con osciloscopio en microsegundos
+const int head_L = 2340;//-10%  medida con osciloscopio
+int i=0;
+const int T_alto=1370;//ponga su tiempo de la prueba
+const int T_bajo=733;//ponga su tiempo de la prueba
+const int num_bits = 7;//ponga su numero de bits
+int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
+int numb[num_bits]; // cadena para almacenar los bits 
+int num1[] = {1,0,1,0,1,0,0};
+int num2[] = {0,1,1,0,1,1,0};    // aqui se configura la trama de bit que representa al boton 1, 2 y 3.
+int num3[] = {0,0,1,0,1,0,0};
+
+int suma1=0;
+int suma2=0;
+int suma3=0;
+int s1t, s2t;
+
+int dato; // tiempo de cada dato que se lee
+
+  
+int main(){
+  
+      led3=1;
+      led4=1;
+      led5=1;
+      
+    
+while(1){
+
+int s1 = 0;
+int s2 = 0;
+int p = 0;
+int q = 0;
+    
+    suma1=suma2=suma3=0;
+    
+ini1: fflush( stdin );
+      
+      header=0;
+      
+      header = irda.read_low_us();    //funcion para leer un pulso de caida o bajo en header
+      if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20%
+      else goto ini1;
+      
+seguir:
+       //leo los datos de la trama y se meten a un arreglo
+      wait_us(570);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 
+      
+      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 luego 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");
+           s1 = num[i] + s1;
+           p++;
+      }
+      
+      else{
+           
+           pc.printf("0");
+           s2 = num[i] + s2;
+           q++;
+        }
+      
+      }
+      
+      
+      s1t = s1/p;
+      s2t = s2/q;
+      
+      for(i=0;i<=(num_bits-1);++i){
+      
+         if (num[i] > ((T_alto+T_bajo)/2)) numb[i]=1;
+         else  numb[i]=0;
+      }
+      
+      for(i=0;i<=(num_bits-1);++i){
+      
+      if (numb[i] == num1[i]) suma1++;
+      if (numb[i] == num2[i]) suma2++;
+      if (numb[i] == num3[i]) suma3++;
+      }
+      pc.printf("%d,%d,%d\n", suma1, suma2, suma3);
+      if (suma1 == num_bits){
+           
+      lcd.cls();
+      led3 = !led3;
+      lcd.locate(0,0);        // Ubica e imprime nombre de los parámetros en del control en la pantalla LCD
+      lcd.printf("#bits");
+      lcd.locate(0,1);
+      lcd.printf("codigo=");
+      
+        lcd.locate(5,0);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",num_bits);
+        lcd.locate(6,0);
+        lcd.printf("%d",num_bits);
+        lcd.locate(6,1);                //------------- Ubica e imprime el parámetro "codigo" en la pantalla LCD
+        lcd.printf("=1010100");
+    
+    wait(1);
+    
+      lcd.cls();
+      lcd.locate(0,0);        // Ubica e imprime nombre de los parámetros en del control en la pantalla LCD
+      lcd.printf("header=");
+      lcd.locate(0,1);
+      lcd.printf("t1=");
+      lcd.locate(8,1);
+      lcd.printf("t0=");
+      
+        lcd.locate(6,0);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",header);
+        lcd.locate(7,0);
+        lcd.printf("%d",header);
+        lcd.locate(2,1);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",s1t);
+        lcd.locate(3,1);
+        lcd.printf("%d",s1t);
+        lcd.locate(10,1);
+        lcd.printf("=    ",s2t);
+        lcd.locate(11,1);
+        lcd.printf("%d",s2t);
+      
+      }
+      
+      if (suma2 == num_bits){ 
+      
+      lcd.cls();
+      led4 = !led4;
+      lcd.locate(0,0);        // Ubica e imprime nombre de los parámetros en del control en la pantalla LCD
+      lcd.printf("#bits");
+      lcd.locate(0,1);
+      lcd.printf("codigo=");
+      
+        lcd.locate(5,0);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",num_bits);
+        lcd.locate(6,0);
+        lcd.printf("%d",num_bits);
+        lcd.locate(6,1);                //------------- Ubica e imprime el parámetro "codigo" en la pantalla LCD
+        lcd.printf("=0110110");
+
+      wait(1);
+    
+      lcd.cls();
+      lcd.locate(0,0);        // Ubica e imprime nombre de los tiempos en la pantalla LCD
+      lcd.printf("header=");
+      lcd.locate(0,1);
+      lcd.printf("t1=");
+      lcd.locate(8,1);
+      lcd.printf("t0=");
+      
+        lcd.locate(6,0);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",header);
+        lcd.locate(7,0);
+        lcd.printf("%d",header);
+        lcd.locate(2,1);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",s1t);
+        lcd.locate(3,1);
+        lcd.printf("%d",s1t);
+        lcd.locate(10,1);
+        lcd.printf("=    ",s2t);
+        lcd.locate(11,1);
+        lcd.printf("%d",s2t);
+      }
+      
+      if (suma3 == num_bits){
+     
+     lcd.cls();
+     led5 = !led5;
+     lcd.locate(0,0);        // Ubica e imprime nombre de los parámetros en del control en la pantalla LCD
+      lcd.printf("#bits");
+      lcd.locate(0,1);
+      lcd.printf("codigo=");
+      
+        lcd.locate(5,0);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",num_bits);
+        lcd.locate(6,0);
+        lcd.printf("%d",num_bits);
+        lcd.locate(6,1);                //------------- Ubica e imprime el parámetro "codigo" en la pantalla LCD
+        lcd.printf("=0010100");
+
+wait(1);
+    
+      lcd.cls();
+      lcd.locate(0,0);        // Ubica e imprime nombre de los parámetros en del control en la pantalla LCD
+      lcd.printf("header=");
+      lcd.locate(0,1);
+      lcd.printf("t1=");
+      lcd.locate(8,1);
+      lcd.printf("t0=");
+      
+        lcd.locate(6,0);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",header);
+        lcd.locate(7,0);
+        lcd.printf("%d",header);
+        lcd.locate(2,1);                //------------- Ubica e imprime el parámetro "#bits" en la pantalla LCD
+        lcd.printf("=    ",s1t);
+        lcd.locate(3,1);
+        lcd.printf("%d",s1t);
+        lcd.locate(10,1);
+        lcd.printf("=    ",s2t);
+        lcd.locate(11,1);
+        lcd.printf("%d",s2t);
+      
+        }  
+      
+      }
+      }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 16 15:42:27 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file