Encendido y apagado de luz led haciendo uso de un control remoto

Dependencies:   Pulse1 TextLCD mbed

Fork of Tarea_6_control_remoto by Mauricio Escobar

Revision:
0:f25302b74b6f
Child:
1:be954ee8585a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 21 15:55:49 2014 +0000
@@ -0,0 +1,148 @@
+#include "mbed.h"
+#include <Pulse1.h>
+#include "TextLCD.h"
+
+
+TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7#include "TextLCD.h"
+
+PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
+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=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 T1=96;
+const int T2=117;
+const int T3=109;
+
+int dato; // tiempo de cada dato que se lee
+  
+int main()
+{
+      
+      led=1;
+      led2=1;
+      led3=1;       
+while(1)
+    {
+            lcd.cls();
+            lcd.locate(0,0);
+            lcd.printf("PULSE UNA TECLA");
+          
+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(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO 
+      //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); //se espera un tiempo 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==T1)
+      {     led=!led;
+            lcd.cls();
+            lcd.printf("PRESIONASTE 1"); 
+            lcd.locate(0,1);
+            lcd.printf("Codigo=%d",Tecla);
+            wait(3);
+            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(3);
+            Tecla=0;
+      }
+      if(Tecla==T2)
+      {
+            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==T3)
+      {
+            
+            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!=T3)&&(Tecla!=T2)&&(Tecla!=T1)&&(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