Tarea6_ModoInfrarrojo, en el cual con tres teclas, enciendo tres leds en modo toogle.

Dependencies:   Pulse1 TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
Jesse
Date:
Wed May 14 15:35:31 2014 +0000
Commit message:
Tarea 6_ModoInfrarrojo

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	Wed May 14 15:35:31 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	Wed May 14 15:35:31 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/lcorralesc1/code/TextLCD/#0e0132807662
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 14 15:35:31 2014 +0000
@@ -0,0 +1,161 @@
+//Michelle Maceas Henao
+//Jesse Mauricio Beltran Soto
+
+#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=1570;//1630;//ponga su tiempo de la prueba
+const int T_bajo=467;//533;//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 num2[num_bits];//Cadena para almacenar datos
+//int numA[num_bits]={1,0,0,0};
+int Num=0;
+const int A=170;
+const int B=205;
+const int C=200;
+int C1=0,flag1=0;
+int C2=0,flag2=0;
+int C3=0,flag3=0;
+int flagg=0;
+
+int dato; // tiempo de cada dato que se lee
+  
+int main()
+{
+      led2=1; //Apago los leds.
+      led=1;
+      led3=1;
+      
+  
+
+      
+while(1)
+    {
+        
+       if(flagg==0)
+       {
+            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);
+       } 
+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();
+      Num=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 
+      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");
+                 num2[i]=1;
+                 if(i>17)
+                 {
+                    Num=Num+1*(2^(i));
+                 }
+            }
+            else 
+            {
+                pc.printf("0");
+            }
+            
+      }
+      
+      if(Num==A)
+      {
+            flagg=1;
+            lcd.cls();
+            lcd.printf("  LED ROJO");
+            lcd.locate(0,1);
+            lcd.printf(" [Decimal]:%d",Num);
+            led=0;
+            C1=C1+1;
+            Num=0;   
+      }
+      if(Num==B)
+      {
+            flagg=1;
+            lcd.cls();
+            lcd.printf("  LED VERDE");
+            lcd.locate(0,1);
+            lcd.printf(" [Decimal]:%d",Num);
+            Num=0; 
+            led2=0;
+            C2=C2+1;
+            Num=0;           
+      }
+      if(Num==C)
+      {
+            flagg=1;
+            lcd.cls();
+            lcd.printf("  LED AZUL");
+            lcd.locate(0,1);
+            lcd.printf(" [Decimal]:%d",Num);
+            led3=0;
+            C3=C3+1;
+            Num=0;       
+      }
+      if(C1==2)
+      {
+        led=1; 
+        C1=0; 
+      }
+       if(C2==2)
+      {
+        led2=1; 
+        C2=0; 
+      }
+       if(C3==2)
+      {
+        led3=1; 
+        C3=0; 
+      }
+      if((C1==0)&&(C2==0)&&(C3==0))
+      {
+          flagg=0;
+      }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed May 14 15:35:31 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file