practica_controlremoto
Dependencies: Pulse1 TextLCD mbed
Fork of control_irda by
main.cpp@6:1cf5b602a007, 2014-05-28 (annotated)
- Committer:
- juanco
- Date:
- Wed May 28 16:44:55 2014 +0000
- Revision:
- 6:1cf5b602a007
- Parent:
- 5:85c0acb48e40
tarea_control;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tony63 | 0:74d57f8ae247 | 1 | #include "mbed.h" |
tony63 | 0:74d57f8ae247 | 2 | #include <Pulse1.h> |
diego_carvajal | 4:f802aeaec9d0 | 3 | #include "TextLCD.h" |
diego_carvajal | 4:f802aeaec9d0 | 4 | |
diego_carvajal | 4:f802aeaec9d0 | 5 | |
jana | 5:85c0acb48e40 | 6 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); |
tony63 | 2:6a15ab0305c8 | 7 | PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo |
jana | 5:85c0acb48e40 | 8 | DigitalOut led1(LED1); |
tony63 | 2:6a15ab0305c8 | 9 | DigitalOut led2(LED2); |
diego_carvajal | 4:f802aeaec9d0 | 10 | DigitalOut led3(LED3); |
diego_carvajal | 4:f802aeaec9d0 | 11 | |
tony63 | 2:6a15ab0305c8 | 12 | int header =0; //tiempo de cabecera pulso abajo |
jana | 5:85c0acb48e40 | 13 | const int head_H = 4600; //+10% medida con osciloscopio en microsegundos |
jana | 5:85c0acb48e40 | 14 | const int head_L = 4400;//-10% medida con osciloscopio |
diego_carvajal | 4:f802aeaec9d0 | 15 | const int Tp=300; |
tony63 | 2:6a15ab0305c8 | 16 | int i=0; |
jana | 5:85c0acb48e40 | 17 | const int T_alto=1630;//1630;//ponga su tiempo de la prueba |
jana | 5:85c0acb48e40 | 18 | const int T_bajo=500;//533;//ponga su tiempo de la prueba |
jana | 5:85c0acb48e40 | 19 | const int num_bits = 25;//ponga su numero de bits |
tony63 | 2:6a15ab0305c8 | 20 | int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos |
diego_carvajal | 4:f802aeaec9d0 | 21 | |
jana | 5:85c0acb48e40 | 22 | int boton=0; |
juanco | 6:1cf5b602a007 | 23 | const int dec1=133; |
juanco | 6:1cf5b602a007 | 24 | const int dec2=142; |
juanco | 6:1cf5b602a007 | 25 | const int dec3=134; |
diego_carvajal | 4:f802aeaec9d0 | 26 | |
tony63 | 2:6a15ab0305c8 | 27 | int dato; // tiempo de cada dato que se lee |
tony63 | 0:74d57f8ae247 | 28 | |
diego_carvajal | 4:f802aeaec9d0 | 29 | int main() |
diego_carvajal | 4:f802aeaec9d0 | 30 | { |
diego_carvajal | 4:f802aeaec9d0 | 31 | |
jana | 5:85c0acb48e40 | 32 | led1=0; |
jana | 5:85c0acb48e40 | 33 | led2=0; |
jana | 5:85c0acb48e40 | 34 | led3=0; |
jana | 5:85c0acb48e40 | 35 | while(1) |
diego_carvajal | 4:f802aeaec9d0 | 36 | { |
diego_carvajal | 4:f802aeaec9d0 | 37 | |
diego_carvajal | 4:f802aeaec9d0 | 38 | |
jana | 5:85c0acb48e40 | 39 | lcd.cls(); |
jana | 5:85c0acb48e40 | 40 | lcd.locate(2,0); |
juanco | 6:1cf5b602a007 | 41 | lcd.printf("Control"); |
jana | 5:85c0acb48e40 | 42 | wait(3); |
jana | 5:85c0acb48e40 | 43 | lcd.cls(); |
jana | 5:85c0acb48e40 | 44 | lcd.locate(0,0); |
juanco | 6:1cf5b602a007 | 45 | lcd.printf("Teclas 1__ 2 __3"); |
diego_carvajal | 4:f802aeaec9d0 | 46 | |
tony63 | 3:82bebaf2a06a | 47 | ini1: fflush( stdin ); |
tony63 | 3:82bebaf2a06a | 48 | header=0; |
tony63 | 3:82bebaf2a06a | 49 | header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header |
tony63 | 2:6a15ab0305c8 | 50 | if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% |
tony63 | 2:6a15ab0305c8 | 51 | else goto ini1; |
tony63 | 0:74d57f8ae247 | 52 | |
tony63 | 2:6a15ab0305c8 | 53 | seguir: |
tony63 | 2:6a15ab0305c8 | 54 | //leo los datos de la trama y se meten a un arreglo |
tony63 | 3:82bebaf2a06a | 55 | wait_us(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO |
diego_carvajal | 4:f802aeaec9d0 | 56 | //led2=0; |
diego_carvajal | 4:f802aeaec9d0 | 57 | lcd.cls(); |
jana | 5:85c0acb48e40 | 58 | boton=0; |
diego_carvajal | 4:f802aeaec9d0 | 59 | for(i=0;i<(num_bits-1);++i) |
diego_carvajal | 4:f802aeaec9d0 | 60 | { // POR OSCILOSCOPIO se determina que llegan (num_bits),datos |
diego_carvajal | 4:f802aeaec9d0 | 61 | dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control |
diego_carvajal | 4:f802aeaec9d0 | 62 | num[i]=dato; |
diego_carvajal | 4:f802aeaec9d0 | 63 | wait_us(Tp); |
diego_carvajal | 4:f802aeaec9d0 | 64 | } |
diego_carvajal | 4:f802aeaec9d0 | 65 | wait(0.3); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla |
diego_carvajal | 4:f802aeaec9d0 | 66 | |
diego_carvajal | 4:f802aeaec9d0 | 67 | for(i=0;i<(num_bits-1);++i) |
diego_carvajal | 4:f802aeaec9d0 | 68 | { |
diego_carvajal | 4:f802aeaec9d0 | 69 | |
diego_carvajal | 4:f802aeaec9d0 | 70 | if(num[i] > ((T_alto+T_bajo)/2)) |
diego_carvajal | 4:f802aeaec9d0 | 71 | { |
jana | 5:85c0acb48e40 | 72 | boton=boton+ (2^(i)); |
diego_carvajal | 4:f802aeaec9d0 | 73 | } |
diego_carvajal | 4:f802aeaec9d0 | 74 | |
diego_carvajal | 4:f802aeaec9d0 | 75 | } |
jana | 5:85c0acb48e40 | 76 | if(boton==dec1) |
jana | 5:85c0acb48e40 | 77 | { led1=!led1; |
jana | 5:85c0acb48e40 | 78 | lcd.cls(); |
jana | 5:85c0acb48e40 | 79 | lcd.printf("Presiono 1"); |
jana | 5:85c0acb48e40 | 80 | lcd.locate(0,1); |
jana | 5:85c0acb48e40 | 81 | lcd.printf("nbit=%d",num_bits); |
jana | 5:85c0acb48e40 | 82 | wait(2); |
jana | 5:85c0acb48e40 | 83 | lcd.cls(); |
jana | 5:85c0acb48e40 | 84 | lcd.locate(0,0); |
jana | 5:85c0acb48e40 | 85 | lcd.printf("HH:%d",head_H); |
jana | 5:85c0acb48e40 | 86 | lcd.locate(8,0); |
jana | 5:85c0acb48e40 | 87 | lcd.printf("1log:%d",T_alto); |
jana | 5:85c0acb48e40 | 88 | lcd.locate(0,1); |
jana | 5:85c0acb48e40 | 89 | lcd.printf("HL:%d",head_L); |
jana | 5:85c0acb48e40 | 90 | lcd.locate(8,1); |
jana | 5:85c0acb48e40 | 91 | lcd.printf("0log:%d",T_alto); |
jana | 5:85c0acb48e40 | 92 | wait(2); |
jana | 5:85c0acb48e40 | 93 | boton=0; |
jana | 5:85c0acb48e40 | 94 | led1=0; |
jana | 5:85c0acb48e40 | 95 | } |
jana | 5:85c0acb48e40 | 96 | |
jana | 5:85c0acb48e40 | 97 | if(boton==dec2) |
jana | 5:85c0acb48e40 | 98 | { |
jana | 5:85c0acb48e40 | 99 | led2=!led2; |
jana | 5:85c0acb48e40 | 100 | lcd.cls(); |
jana | 5:85c0acb48e40 | 101 | lcd.printf("Presiono 2"); |
jana | 5:85c0acb48e40 | 102 | lcd.locate(0,1); |
jana | 5:85c0acb48e40 | 103 | lcd.printf("nbit=%d",num_bits); |
jana | 5:85c0acb48e40 | 104 | wait(2); |
jana | 5:85c0acb48e40 | 105 | lcd.cls(); |
jana | 5:85c0acb48e40 | 106 | lcd.locate(0,0); |
jana | 5:85c0acb48e40 | 107 | lcd.printf("HH:%d",head_H); |
jana | 5:85c0acb48e40 | 108 | lcd.locate(8,0); |
jana | 5:85c0acb48e40 | 109 | lcd.printf("1log:%d",T_alto); |
jana | 5:85c0acb48e40 | 110 | lcd.locate(0,1); |
jana | 5:85c0acb48e40 | 111 | lcd.printf("HL:%d",head_L); |
jana | 5:85c0acb48e40 | 112 | lcd.locate(8,1); |
jana | 5:85c0acb48e40 | 113 | lcd.printf("0log:%d",T_alto); |
jana | 5:85c0acb48e40 | 114 | wait(2); |
jana | 5:85c0acb48e40 | 115 | boton=0; |
jana | 5:85c0acb48e40 | 116 | led2=0; |
jana | 5:85c0acb48e40 | 117 | } |
jana | 5:85c0acb48e40 | 118 | |
juanco | 6:1cf5b602a007 | 119 | if(boton==dec3) |
jana | 5:85c0acb48e40 | 120 | { |
jana | 5:85c0acb48e40 | 121 | led3=!led3; |
jana | 5:85c0acb48e40 | 122 | lcd.cls(); |
juanco | 6:1cf5b602a007 | 123 | lcd.printf("Presiono 3"); |
jana | 5:85c0acb48e40 | 124 | lcd.locate(0,1); |
jana | 5:85c0acb48e40 | 125 | lcd.printf("nbit=%d",num_bits); |
jana | 5:85c0acb48e40 | 126 | wait(2); |
jana | 5:85c0acb48e40 | 127 | lcd.cls(); |
jana | 5:85c0acb48e40 | 128 | lcd.locate(0,0); |
jana | 5:85c0acb48e40 | 129 | lcd.printf("HH:%d",head_H); |
jana | 5:85c0acb48e40 | 130 | lcd.locate(8,0); |
jana | 5:85c0acb48e40 | 131 | lcd.printf("1log:%d",T_alto); |
jana | 5:85c0acb48e40 | 132 | lcd.locate(0,1); |
jana | 5:85c0acb48e40 | 133 | lcd.printf("HL:%d",head_L); |
jana | 5:85c0acb48e40 | 134 | lcd.locate(8,1); |
jana | 5:85c0acb48e40 | 135 | lcd.printf("0log:%d",T_alto); |
jana | 5:85c0acb48e40 | 136 | wait(2); |
jana | 5:85c0acb48e40 | 137 | boton=0; |
jana | 5:85c0acb48e40 | 138 | led3=0; |
jana | 5:85c0acb48e40 | 139 | } |
jana | 5:85c0acb48e40 | 140 | |
juanco | 6:1cf5b602a007 | 141 | if ((boton!=dec3)&&(boton!=dec2)&&(boton!=dec1)&&(boton!=0)) |
jana | 5:85c0acb48e40 | 142 | { |
jana | 5:85c0acb48e40 | 143 | lcd.cls(); |
jana | 5:85c0acb48e40 | 144 | lcd.printf("tecla no progamada"); |
jana | 5:85c0acb48e40 | 145 | lcd.locate(0,1); |
juanco | 6:1cf5b602a007 | 146 | lcd.printf("nbit=%d",boton); |
jana | 5:85c0acb48e40 | 147 | wait(2); |
jana | 5:85c0acb48e40 | 148 | lcd.cls(); |
jana | 5:85c0acb48e40 | 149 | lcd.locate(0,0); |
jana | 5:85c0acb48e40 | 150 | lcd.printf("HH:%d",head_H); |
jana | 5:85c0acb48e40 | 151 | lcd.locate(8,0); |
jana | 5:85c0acb48e40 | 152 | lcd.printf("1log:%d",T_alto); |
jana | 5:85c0acb48e40 | 153 | lcd.locate(0,1); |
jana | 5:85c0acb48e40 | 154 | lcd.printf("HL:%d",head_L); |
jana | 5:85c0acb48e40 | 155 | lcd.locate(8,1); |
jana | 5:85c0acb48e40 | 156 | lcd.printf("0log:%d",T_alto); |
jana | 5:85c0acb48e40 | 157 | wait(2); |
jana | 5:85c0acb48e40 | 158 | boton=0; |
jana | 5:85c0acb48e40 | 159 | } |
diego_carvajal | 4:f802aeaec9d0 | 160 | } |
diego_carvajal | 4:f802aeaec9d0 | 161 | } |