practica_controlremoto

Dependencies:   Pulse1 TextLCD mbed

Fork of control_irda by Johana Cano Velez

Revision:
5:85c0acb48e40
Parent:
4:f802aeaec9d0
Child:
6:1cf5b602a007
--- a/main.cpp	Wed May 14 16:26:50 2014 +0000
+++ b/main.cpp	Fri May 23 18:26:17 2014 +0000
@@ -1,49 +1,48 @@
-// 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
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); 
 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
-DigitalOut led(LED1);
+DigitalOut led1(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 head_H = 4600; //+10% medida con osciloscopio en microsegundos
+const int head_L = 4400;//-10%  medida con osciloscopio
 const int Tp=300;
 int i=0;
-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
+const int T_alto=1630;//1630;//ponga su tiempo de la prueba
+const int T_bajo=500;//533;//ponga su tiempo de la prueba
+const int num_bits = 25;//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 boton=0;
+const int dec1=55;
+const int dec2=47;
+const int dec4=39;
 
 int dato; // tiempo de cada dato que se lee
   
 int main()
 {
       
-      led=1;
-      led2=1;
-      led3=1;       
-while(1)
+      led1=0;
+      led2=0;
+      led3=0;       
+    while(1)
     {
         
       
-       
-            lcd.cls();
-            lcd.locate(0,0);
-            lcd.printf("PRESIONE TECLA");
+        lcd.cls();
+        lcd.locate(2,0);
+        lcd.printf("Control Irda");
+        wait(3);
+        lcd.cls();
+        lcd.locate(0,0);
+        lcd.printf("Teclas 1 2 o 4");
           
 ini1: fflush( stdin );
       header=0;
@@ -56,7 +55,7 @@
       wait_us(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 
       //led2=0;
       lcd.cls();
-      Tecla=0;
+      boton=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
@@ -70,86 +69,93 @@
         
         if(num[i] > ((T_alto+T_bajo)/2))
             {
-                    Tecla=Tecla+ (2^(i));
+                    boton=boton+ (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;
-      }
-      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);
-      }
-      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);      
-      }
-      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);}
+                    if(boton==dec1)
+                    {    led1=!led1;
+                         lcd.cls();
+                         lcd.printf("Presiono 1"); 
+                         lcd.locate(0,1);
+                         lcd.printf("nbit=%d",num_bits);
+                         wait(2);
+                         lcd.cls();
+                         lcd.locate(0,0);
+                         lcd.printf("HH:%d",head_H);
+                         lcd.locate(8,0);
+                         lcd.printf("1log:%d",T_alto);
+                         lcd.locate(0,1);
+                         lcd.printf("HL:%d",head_L);
+                         lcd.locate(8,1);
+                         lcd.printf("0log:%d",T_alto);
+                         wait(2);
+                         boton=0;
+                         led1=0;
+                  }
+                  
+                    if(boton==dec2)
+                     {
+                        led2=!led2;
+                        lcd.cls();
+                        lcd.printf("Presiono 2"); 
+                        lcd.locate(0,1);
+                        lcd.printf("nbit=%d",num_bits);
+                        wait(2);
+                        lcd.cls();
+                        lcd.locate(0,0);
+                        lcd.printf("HH:%d",head_H);
+                        lcd.locate(8,0);
+                        lcd.printf("1log:%d",T_alto);
+                        lcd.locate(0,1);
+                        lcd.printf("HL:%d",head_L);
+                        lcd.locate(8,1);
+                        lcd.printf("0log:%d",T_alto);
+                        wait(2);
+                        boton=0;
+                        led2=0;
+                }
+                
+              if(boton==dec4)
+                 {
+                        led3=!led3;
+                        lcd.cls();
+                        lcd.printf("Presiono 4"); 
+                        lcd.locate(0,1);
+                        lcd.printf("nbit=%d",num_bits);
+                        wait(2);
+                        lcd.cls();
+                        lcd.locate(0,0);
+                        lcd.printf("HH:%d",head_H);
+                        lcd.locate(8,0);
+                        lcd.printf("1log:%d",T_alto);
+                        lcd.locate(0,1);
+                        lcd.printf("HL:%d",head_L);
+                        lcd.locate(8,1);
+                        lcd.printf("0log:%d",T_alto);
+                        wait(2);
+                        boton=0;
+                        led3=0;    
+                 }
+                    
+                if ((boton!=dec4)&&(boton!=dec2)&&(boton!=dec1)&&(boton!=0))
+                { 
+                       lcd.cls();
+                       lcd.printf("tecla no progamada");
+                       lcd.locate(0,1);
+                       lcd.printf("nbit=%d",num_bits);
+                       wait(2);
+                       lcd.cls();
+                       lcd.locate(0,0);
+                       lcd.printf("HH:%d",head_H);
+                       lcd.locate(8,0);
+                       lcd.printf("1log:%d",T_alto);
+                       lcd.locate(0,1);
+                       lcd.printf("HL:%d",head_L);
+                       lcd.locate(8,1);
+                       lcd.printf("0log:%d",T_alto);
+                       wait(2);
+                       boton=0;
+             }
     }
 }
\ No newline at end of file