Programa para detectar tres teclas deun control LG

Dependencies:   Pulse1 TextLCD mbed

Fork of irda_V_aula by Gustavo Ramirez

Committer:
diego_carvajal
Date:
Wed May 14 16:26:50 2014 +0000
Revision:
4:f802aeaec9d0
Parent:
3:82bebaf2a06a
6Tarea:Infrarojo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
diego_carvajal 4:f802aeaec9d0 1 // Santiago Lopez Restrepo
diego_carvajal 4:f802aeaec9d0 2 // Diego Fernando Carvajal Castrillon
diego_carvajal 4:f802aeaec9d0 3
tony63 0:74d57f8ae247 4 #include "mbed.h"
tony63 0:74d57f8ae247 5 #include <Pulse1.h>
diego_carvajal 4:f802aeaec9d0 6 #include "TextLCD.h"
diego_carvajal 4:f802aeaec9d0 7
diego_carvajal 4:f802aeaec9d0 8
diego_carvajal 4:f802aeaec9d0 9 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7#include "TextLCD.h"
tony63 3:82bebaf2a06a 10 //control remoto videobeam aula
tony63 2:6a15ab0305c8 11 PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
tony63 0:74d57f8ae247 12 DigitalOut led(LED1);
tony63 2:6a15ab0305c8 13 DigitalOut led2(LED2);
diego_carvajal 4:f802aeaec9d0 14 DigitalOut led3(LED3);
diego_carvajal 4:f802aeaec9d0 15
tony63 2:6a15ab0305c8 16 int header =0; //tiempo de cabecera pulso abajo
tony63 3:82bebaf2a06a 17 const int head_H = 9120; //+10% medida con osciloscopio en microsegundos
tony63 3:82bebaf2a06a 18 const int head_L = 8939;//-10% medida con osciloscopio
diego_carvajal 4:f802aeaec9d0 19 const int Tp=300;
tony63 2:6a15ab0305c8 20 int i=0;
diego_carvajal 4:f802aeaec9d0 21 const int T_alto=1570;//1630;//ponga su tiempo de la prueba
diego_carvajal 4:f802aeaec9d0 22 const int T_bajo=467;//533;//ponga su tiempo de la prueba
diego_carvajal 4:f802aeaec9d0 23 const int num_bits = 24;//ponga su numero de bits
tony63 2:6a15ab0305c8 24 int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
diego_carvajal 4:f802aeaec9d0 25
diego_carvajal 4:f802aeaec9d0 26 int Tecla=0;
diego_carvajal 4:f802aeaec9d0 27 const int N1=96;
diego_carvajal 4:f802aeaec9d0 28 const int N2=117;
diego_carvajal 4:f802aeaec9d0 29 const int N3=109;
diego_carvajal 4:f802aeaec9d0 30
tony63 2:6a15ab0305c8 31 int dato; // tiempo de cada dato que se lee
tony63 0:74d57f8ae247 32
diego_carvajal 4:f802aeaec9d0 33 int main()
diego_carvajal 4:f802aeaec9d0 34 {
diego_carvajal 4:f802aeaec9d0 35
diego_carvajal 4:f802aeaec9d0 36 led=1;
diego_carvajal 4:f802aeaec9d0 37 led2=1;
diego_carvajal 4:f802aeaec9d0 38 led3=1;
diego_carvajal 4:f802aeaec9d0 39 while(1)
diego_carvajal 4:f802aeaec9d0 40 {
diego_carvajal 4:f802aeaec9d0 41
diego_carvajal 4:f802aeaec9d0 42
diego_carvajal 4:f802aeaec9d0 43
diego_carvajal 4:f802aeaec9d0 44 lcd.cls();
diego_carvajal 4:f802aeaec9d0 45 lcd.locate(0,0);
diego_carvajal 4:f802aeaec9d0 46 lcd.printf("PRESIONE TECLA");
diego_carvajal 4:f802aeaec9d0 47
tony63 3:82bebaf2a06a 48 ini1: fflush( stdin );
tony63 3:82bebaf2a06a 49 header=0;
tony63 3:82bebaf2a06a 50 header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header
tony63 2:6a15ab0305c8 51 if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20%
tony63 2:6a15ab0305c8 52 else goto ini1;
tony63 0:74d57f8ae247 53
tony63 2:6a15ab0305c8 54 seguir:
tony63 2:6a15ab0305c8 55 //leo los datos de la trama y se meten a un arreglo
tony63 3:82bebaf2a06a 56 wait_us(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO
diego_carvajal 4:f802aeaec9d0 57 //led2=0;
diego_carvajal 4:f802aeaec9d0 58 lcd.cls();
diego_carvajal 4:f802aeaec9d0 59 Tecla=0;
diego_carvajal 4:f802aeaec9d0 60 for(i=0;i<(num_bits-1);++i)
diego_carvajal 4:f802aeaec9d0 61 { // POR OSCILOSCOPIO se determina que llegan (num_bits),datos
diego_carvajal 4:f802aeaec9d0 62 dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control
diego_carvajal 4:f802aeaec9d0 63 num[i]=dato;
diego_carvajal 4:f802aeaec9d0 64 wait_us(Tp);
diego_carvajal 4:f802aeaec9d0 65 }
diego_carvajal 4:f802aeaec9d0 66 wait(0.3); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla
diego_carvajal 4:f802aeaec9d0 67
diego_carvajal 4:f802aeaec9d0 68 for(i=0;i<(num_bits-1);++i)
diego_carvajal 4:f802aeaec9d0 69 {
diego_carvajal 4:f802aeaec9d0 70
diego_carvajal 4:f802aeaec9d0 71 if(num[i] > ((T_alto+T_bajo)/2))
diego_carvajal 4:f802aeaec9d0 72 {
diego_carvajal 4:f802aeaec9d0 73 Tecla=Tecla+ (2^(i));
diego_carvajal 4:f802aeaec9d0 74 }
diego_carvajal 4:f802aeaec9d0 75
diego_carvajal 4:f802aeaec9d0 76 }
diego_carvajal 4:f802aeaec9d0 77 if(Tecla==N1)
diego_carvajal 4:f802aeaec9d0 78 { led=!led;
diego_carvajal 4:f802aeaec9d0 79 lcd.cls();
diego_carvajal 4:f802aeaec9d0 80 lcd.printf("PRESIONASTE 1");
diego_carvajal 4:f802aeaec9d0 81 lcd.locate(0,1);
diego_carvajal 4:f802aeaec9d0 82 lcd.printf("Codigo=%d",Tecla);
diego_carvajal 4:f802aeaec9d0 83 wait(2);
diego_carvajal 4:f802aeaec9d0 84 lcd.cls();
diego_carvajal 4:f802aeaec9d0 85 lcd.locate(0,0);
diego_carvajal 4:f802aeaec9d0 86 lcd.printf("HH:%d",head_H);
diego_carvajal 4:f802aeaec9d0 87 lcd.locate(8,0);
diego_carvajal 4:f802aeaec9d0 88 lcd.printf("Tby:%d",Tp);
diego_carvajal 4:f802aeaec9d0 89 lcd.locate(0,1);
diego_carvajal 4:f802aeaec9d0 90 lcd.printf("HL:%d",head_L);
diego_carvajal 4:f802aeaec9d0 91 lcd.locate(8,1);
diego_carvajal 4:f802aeaec9d0 92 lcd.printf("Nby:%d",num_bits);
diego_carvajal 4:f802aeaec9d0 93 wait(2);
diego_carvajal 4:f802aeaec9d0 94 Tecla=0;
tony63 2:6a15ab0305c8 95 }
diego_carvajal 4:f802aeaec9d0 96 if(Tecla==N2)
diego_carvajal 4:f802aeaec9d0 97 {
diego_carvajal 4:f802aeaec9d0 98 led2=!led2;
diego_carvajal 4:f802aeaec9d0 99 lcd.cls();
diego_carvajal 4:f802aeaec9d0 100 lcd.printf("PRESIONASTE 2");
diego_carvajal 4:f802aeaec9d0 101 lcd.locate(0,1);
diego_carvajal 4:f802aeaec9d0 102 lcd.printf("Codigo=%d",Tecla);
diego_carvajal 4:f802aeaec9d0 103 wait(2);
diego_carvajal 4:f802aeaec9d0 104 lcd.cls();
diego_carvajal 4:f802aeaec9d0 105 lcd.locate(0,0);
diego_carvajal 4:f802aeaec9d0 106 lcd.printf("HH:%d",head_H);
diego_carvajal 4:f802aeaec9d0 107 lcd.locate(8,0);
diego_carvajal 4:f802aeaec9d0 108 lcd.printf("Tby:%d",Tp);
diego_carvajal 4:f802aeaec9d0 109 lcd.locate(0,1);
diego_carvajal 4:f802aeaec9d0 110 lcd.printf("HL:%d",head_L);
diego_carvajal 4:f802aeaec9d0 111 lcd.locate(8,1);
diego_carvajal 4:f802aeaec9d0 112 lcd.printf("Nby:%d",num_bits);
diego_carvajal 4:f802aeaec9d0 113 Tecla=0;
diego_carvajal 4:f802aeaec9d0 114 wait(2);
tony63 2:6a15ab0305c8 115 }
diego_carvajal 4:f802aeaec9d0 116 if(Tecla==N3)
diego_carvajal 4:f802aeaec9d0 117 {
diego_carvajal 4:f802aeaec9d0 118
diego_carvajal 4:f802aeaec9d0 119 led3=!led3;
diego_carvajal 4:f802aeaec9d0 120 lcd.cls();
diego_carvajal 4:f802aeaec9d0 121 lcd.printf("PRESIONASTE 3");
diego_carvajal 4:f802aeaec9d0 122 lcd.locate(0,1);
diego_carvajal 4:f802aeaec9d0 123 lcd.printf("Codigo=%d",Tecla);
diego_carvajal 4:f802aeaec9d0 124 wait(2);
diego_carvajal 4:f802aeaec9d0 125 lcd.cls();
diego_carvajal 4:f802aeaec9d0 126 lcd.locate(0,0);
diego_carvajal 4:f802aeaec9d0 127 lcd.printf("HH:%d",head_H);
diego_carvajal 4:f802aeaec9d0 128 lcd.locate(8,0);
diego_carvajal 4:f802aeaec9d0 129 lcd.printf("Tby:%d",Tp);
diego_carvajal 4:f802aeaec9d0 130 lcd.locate(0,1);
diego_carvajal 4:f802aeaec9d0 131 lcd.printf("HL:%d",head_L);
diego_carvajal 4:f802aeaec9d0 132 lcd.locate(8,1);
diego_carvajal 4:f802aeaec9d0 133 lcd.printf("Nby:%d",num_bits);
diego_carvajal 4:f802aeaec9d0 134 Tecla=0;
diego_carvajal 4:f802aeaec9d0 135 wait(2);
tony63 2:6a15ab0305c8 136 }
diego_carvajal 4:f802aeaec9d0 137 if ((Tecla!=N3)&&(Tecla!=N2)&&(Tecla!=N1)&&(Tecla!=0)){
diego_carvajal 4:f802aeaec9d0 138 lcd.cls();
diego_carvajal 4:f802aeaec9d0 139 lcd.printf("TECLA INCORRECTA");
diego_carvajal 4:f802aeaec9d0 140 lcd.locate(0,1);
diego_carvajal 4:f802aeaec9d0 141 lcd.printf("Codigo=%d",Tecla);
diego_carvajal 4:f802aeaec9d0 142 wait(2);
diego_carvajal 4:f802aeaec9d0 143 lcd.cls();
diego_carvajal 4:f802aeaec9d0 144 lcd.locate(0,0);
diego_carvajal 4:f802aeaec9d0 145 lcd.printf("HH:%d",head_H);
diego_carvajal 4:f802aeaec9d0 146 lcd.locate(8,0);
diego_carvajal 4:f802aeaec9d0 147 lcd.printf("Tby:%d",Tp);
diego_carvajal 4:f802aeaec9d0 148 lcd.locate(0,1);
diego_carvajal 4:f802aeaec9d0 149 lcd.printf("HL:%d",head_L);
diego_carvajal 4:f802aeaec9d0 150 lcd.locate(8,1);
diego_carvajal 4:f802aeaec9d0 151 lcd.printf("Nby:%d",num_bits);
diego_carvajal 4:f802aeaec9d0 152 Tecla=0;
diego_carvajal 4:f802aeaec9d0 153 wait(2);}
diego_carvajal 4:f802aeaec9d0 154 }
diego_carvajal 4:f802aeaec9d0 155 }