Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Pulse1 TextLCD mbed
Fork of irda_V_aula by
main.cpp
- Committer:
- diego_carvajal
- Date:
- 2014-05-14
- Revision:
- 4:f802aeaec9d0
- Parent:
- 3:82bebaf2a06a
- Child:
- 5:b43bc33f5002
File content as of revision 4:f802aeaec9d0:
// 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
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 N1=96;
const int N2=117;
const int N3=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("PRESIONE 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); //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;
}
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);}
}
}
