practica_controlremoto

Dependencies:   Pulse1 TextLCD mbed

Fork of control_irda by Johana Cano Velez

Revision:
4:f802aeaec9d0
Parent:
3:82bebaf2a06a
Child:
5:85c0acb48e40
--- a/main.cpp	Thu May 08 00:38:39 2014 +0000
+++ b/main.cpp	Wed May 14 16:26:50 2014 +0000
@@ -1,26 +1,52 @@
+// Santiago Lopez Restrepo
+// Diego Fernando Carvajal Castrillon
+
 #include "mbed.h"
 #include <Pulse1.h>
+#include "TextLCD.h"
+
+
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7#include "TextLCD.h"
 //control remoto videobeam aula
 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
-Serial pc(USBTX, USBRX);
 DigitalOut led(LED1);
 DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+
 int header =0; //tiempo de cabecera pulso abajo
 const int head_H = 9120; //+10% medida con osciloscopio en microsegundos
 const int head_L = 8939;//-10%  medida con osciloscopio
+const int Tp=300;
 int i=0;
-const int T_alto=1630;//ponga su tiempo de la prueba
-const int T_bajo=533;//ponga su tiempo de la prueba
-const int num_bits = 64;//ponga su numero de bits
+const int T_alto=1570;//1630;//ponga su tiempo de la prueba
+const int T_bajo=467;//533;//ponga su tiempo de la prueba
+const int num_bits = 24;//ponga su numero de bits
 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
+
+int Tecla=0;
+const int N1=96;
+const int N2=117;
+const int N3=109;
+
 int dato; // tiempo de cada dato que se lee
   
-int main(){
-while(1){
+int main()
+{
+      
+      led=1;
+      led2=1;
+      led3=1;       
+while(1)
+    {
+        
+      
+       
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("PRESIONE TECLA");
+          
 ini1: fflush( stdin );
       header=0;
-      led2=1;
-      led=1;
       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;
@@ -28,22 +54,102 @@
 seguir:
        //leo los datos de la trama y se meten a un arreglo
       wait_us(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 
-      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);   
+      //led2=0;
+      lcd.cls();
+      Tecla=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(Tp);   
+      }
+      wait(0.3); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla 
+ 
+      for(i=0;i<(num_bits-1);++i)
+      {  
+        
+        if(num[i] > ((T_alto+T_bajo)/2))
+            {
+                    Tecla=Tecla+ (2^(i));
+            }
+          
+      }
+      if(Tecla==N1)
+      {     led=!led;
+            lcd.cls();
+            lcd.printf("PRESIONASTE 1"); 
+            lcd.locate(0,1);
+            lcd.printf("Codigo=%d",Tecla);
+            wait(2);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",head_H);
+            lcd.locate(8,0);
+            lcd.printf("Tby:%d",Tp);
+            lcd.locate(0,1);
+            lcd.printf("HL:%d",head_L);
+            lcd.locate(8,1);
+            lcd.printf("Nby:%d",num_bits);
+            wait(2);
+            Tecla=0;
       }
-      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]);
+      if(Tecla==N2)
+      {
+            led2=!led2;
+            lcd.cls();
+            lcd.printf("PRESIONASTE 2");  
+            lcd.locate(0,1);
+            lcd.printf("Codigo=%d",Tecla);
+            wait(2);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",head_H);
+            lcd.locate(8,0);
+            lcd.printf("Tby:%d",Tp);
+            lcd.locate(0,1);
+            lcd.printf("HL:%d",head_L);
+            lcd.locate(8,1);
+            lcd.printf("Nby:%d",num_bits);      
+            Tecla=0; 
+            wait(2);
       }
-      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");
+      if(Tecla==N3)
+      {
+            
+            led3=!led3;
+            lcd.cls();
+            lcd.printf("PRESIONASTE 3");
+            lcd.locate(0,1);
+            lcd.printf("Codigo=%d",Tecla);
+            wait(2);
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("HH:%d",head_H);
+            lcd.locate(8,0);
+            lcd.printf("Tby:%d",Tp);
+            lcd.locate(0,1);
+            lcd.printf("HL:%d",head_L);
+            lcd.locate(8,1);
+            lcd.printf("Nby:%d",num_bits);
+            Tecla=0; 
+            wait(2);      
       }
-      }
-      }
\ No newline at end of file
+      if ((Tecla!=N3)&&(Tecla!=N2)&&(Tecla!=N1)&&(Tecla!=0)){ 
+      lcd.cls();
+      lcd.printf("TECLA INCORRECTA");
+      lcd.locate(0,1);
+      lcd.printf("Codigo=%d",Tecla);
+      wait(2);
+      lcd.cls();
+      lcd.locate(0,0);
+      lcd.printf("HH:%d",head_H);
+      lcd.locate(8,0);
+      lcd.printf("Tby:%d",Tp);
+      lcd.locate(0,1);
+      lcd.printf("HL:%d",head_L);
+      lcd.locate(8,1);
+      lcd.printf("Nby:%d",num_bits);
+      Tecla=0; 
+      wait(2);}
+    }
+}
\ No newline at end of file