Tarea6-Versión. Usando un receptor infrarrojo y un control remoto mostrar los tiempos en pantalla de cabecera en pantalla.
Dependencies: DebouncedIn Pulse1 TextLCD mbed
main.cpp@0:7af58844bc21, 2014-06-18 (annotated)
- Committer:
- juniorACA
- Date:
- Wed Jun 18 17:44:49 2014 +0000
- Revision:
- 0:7af58844bc21
Tarea 6- Versi?n 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
juniorACA | 0:7af58844bc21 | 1 | #include "mbed.h" |
juniorACA | 0:7af58844bc21 | 2 | #include <Pulse1.h> |
juniorACA | 0:7af58844bc21 | 3 | #include "TextLCD.h" |
juniorACA | 0:7af58844bc21 | 4 | #include "DebouncedIn.h" |
juniorACA | 0:7af58844bc21 | 5 | |
juniorACA | 0:7af58844bc21 | 6 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); |
juniorACA | 0:7af58844bc21 | 7 | PulseInOut irda(PTD5); |
juniorACA | 0:7af58844bc21 | 8 | DigitalOut led1(LED3); //Salida Led Azul |
juniorACA | 0:7af58844bc21 | 9 | DigitalOut led2(LED2); //Salida Led Verde |
juniorACA | 0:7af58844bc21 | 10 | DigitalOut led3(LED1); // Salida Led Rojo |
juniorACA | 0:7af58844bc21 | 11 | PwmOut sonido(PTA12); // Salida sonido |
juniorACA | 0:7af58844bc21 | 12 | const int num_bits = 25; |
juniorACA | 0:7af58844bc21 | 13 | int header =0; //Tiempo Cabecera |
juniorACA | 0:7af58844bc21 | 14 | const int head_L = 4400; // Tiempo de Cabecere alto |
juniorACA | 0:7af58844bc21 | 15 | const int head_H = 4600; // Tiempo de Cabacera bajo |
juniorACA | 0:7af58844bc21 | 16 | const int Tp=300; |
juniorACA | 0:7af58844bc21 | 17 | const int T_bajo=470; |
juniorACA | 0:7af58844bc21 | 18 | const int T_alto=1630; |
juniorACA | 0:7af58844bc21 | 19 | int num[num_bits]; |
juniorACA | 0:7af58844bc21 | 20 | int i=0; |
juniorACA | 0:7af58844bc21 | 21 | //Programación de teclas |
juniorACA | 0:7af58844bc21 | 22 | int Tecla=0; |
juniorACA | 0:7af58844bc21 | 23 | const int T1=10;// |
juniorACA | 0:7af58844bc21 | 24 | const int T2=28; |
juniorACA | 0:7af58844bc21 | 25 | const int T3=44; |
juniorACA | 0:7af58844bc21 | 26 | |
juniorACA | 0:7af58844bc21 | 27 | int dato; |
juniorACA | 0:7af58844bc21 | 28 | float Dd=10; |
juniorACA | 0:7af58844bc21 | 29 | float pp=30; |
juniorACA | 0:7af58844bc21 | 30 | float Fi; |
juniorACA | 0:7af58844bc21 | 31 | |
juniorACA | 0:7af58844bc21 | 32 | int main() |
juniorACA | 0:7af58844bc21 | 33 | { |
juniorACA | 0:7af58844bc21 | 34 | led1=1; |
juniorACA | 0:7af58844bc21 | 35 | led2=1; |
juniorACA | 0:7af58844bc21 | 36 | led3=1; |
juniorACA | 0:7af58844bc21 | 37 | while(1) |
juniorACA | 0:7af58844bc21 | 38 | { |
juniorACA | 0:7af58844bc21 | 39 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 40 | lcd.locate(0,0); |
juniorACA | 0:7af58844bc21 | 41 | lcd.printf("Presionar Boton"); |
juniorACA | 0:7af58844bc21 | 42 | |
juniorACA | 0:7af58844bc21 | 43 | |
juniorACA | 0:7af58844bc21 | 44 | |
juniorACA | 0:7af58844bc21 | 45 | ini1: fflush( stdin ); |
juniorACA | 0:7af58844bc21 | 46 | header=0; |
juniorACA | 0:7af58844bc21 | 47 | header = irda.read_low_us(); |
juniorACA | 0:7af58844bc21 | 48 | if (header > head_L && header < head_H) goto seguir; |
juniorACA | 0:7af58844bc21 | 49 | else goto ini1; |
juniorACA | 0:7af58844bc21 | 50 | |
juniorACA | 0:7af58844bc21 | 51 | seguir: |
juniorACA | 0:7af58844bc21 | 52 | |
juniorACA | 0:7af58844bc21 | 53 | wait_us(3000); |
juniorACA | 0:7af58844bc21 | 54 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 55 | Tecla=0; |
juniorACA | 0:7af58844bc21 | 56 | for(i=0;i<(num_bits-1);++i) |
juniorACA | 0:7af58844bc21 | 57 | { |
juniorACA | 0:7af58844bc21 | 58 | dato = irda.read_high_us(); |
juniorACA | 0:7af58844bc21 | 59 | num[i]=dato; |
juniorACA | 0:7af58844bc21 | 60 | wait_us(Tp); |
juniorACA | 0:7af58844bc21 | 61 | } |
juniorACA | 0:7af58844bc21 | 62 | wait(0.5); |
juniorACA | 0:7af58844bc21 | 63 | |
juniorACA | 0:7af58844bc21 | 64 | for(i=0;i<(num_bits-1);++i) |
juniorACA | 0:7af58844bc21 | 65 | { |
juniorACA | 0:7af58844bc21 | 66 | |
juniorACA | 0:7af58844bc21 | 67 | if(num[i] > ((T_alto+T_bajo)/2)) |
juniorACA | 0:7af58844bc21 | 68 | { |
juniorACA | 0:7af58844bc21 | 69 | Tecla=Tecla+ (2^(i)); |
juniorACA | 0:7af58844bc21 | 70 | } |
juniorACA | 0:7af58844bc21 | 71 | } |
juniorACA | 0:7af58844bc21 | 72 | if(Tecla==T1) |
juniorACA | 0:7af58844bc21 | 73 | |
juniorACA | 0:7af58844bc21 | 74 | { Fi=(Dd)*100; |
juniorACA | 0:7af58844bc21 | 75 | pp=(1/Fi); |
juniorACA | 0:7af58844bc21 | 76 | sonido.period(pp); |
juniorACA | 0:7af58844bc21 | 77 | sonido.write(0.1); |
juniorACA | 0:7af58844bc21 | 78 | wait(0.1); |
juniorACA | 0:7af58844bc21 | 79 | sonido.write(0); |
juniorACA | 0:7af58844bc21 | 80 | wait(0.1); |
juniorACA | 0:7af58844bc21 | 81 | led1=!led1; |
juniorACA | 0:7af58844bc21 | 82 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 83 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 84 | lcd.printf("Boton 1"); |
juniorACA | 0:7af58844bc21 | 85 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 86 | lcd.printf("Codigo=%d",Tecla); |
juniorACA | 0:7af58844bc21 | 87 | wait(3); |
juniorACA | 0:7af58844bc21 | 88 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 89 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 90 | lcd.printf("HL:%d",head_L); |
juniorACA | 0:7af58844bc21 | 91 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 92 | lcd.printf("HH:%d",head_H); |
juniorACA | 0:7af58844bc21 | 93 | wait(3); |
juniorACA | 0:7af58844bc21 | 94 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 95 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 96 | lcd.printf("Tbi:%d",Tp); |
juniorACA | 0:7af58844bc21 | 97 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 98 | lcd.printf("Nbi:%d",num_bits); |
juniorACA | 0:7af58844bc21 | 99 | wait(3); |
juniorACA | 0:7af58844bc21 | 100 | Tecla=0; |
juniorACA | 0:7af58844bc21 | 101 | } |
juniorACA | 0:7af58844bc21 | 102 | if(Tecla==T2) |
juniorACA | 0:7af58844bc21 | 103 | { Fi=(Dd)*100; |
juniorACA | 0:7af58844bc21 | 104 | pp=(1/Fi); |
juniorACA | 0:7af58844bc21 | 105 | sonido.period(pp); |
juniorACA | 0:7af58844bc21 | 106 | sonido.write(0.1); |
juniorACA | 0:7af58844bc21 | 107 | wait(0.1); |
juniorACA | 0:7af58844bc21 | 108 | sonido.write(0); |
juniorACA | 0:7af58844bc21 | 109 | wait(0.1); |
juniorACA | 0:7af58844bc21 | 110 | led2=!led2; |
juniorACA | 0:7af58844bc21 | 111 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 112 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 113 | lcd.printf("Boton 2"); |
juniorACA | 0:7af58844bc21 | 114 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 115 | lcd.printf("Codigo=%d",Tecla); |
juniorACA | 0:7af58844bc21 | 116 | wait(3); |
juniorACA | 0:7af58844bc21 | 117 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 118 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 119 | lcd.printf("HL:%d",head_L); |
juniorACA | 0:7af58844bc21 | 120 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 121 | lcd.printf("HH:%d",head_H); |
juniorACA | 0:7af58844bc21 | 122 | wait(3); |
juniorACA | 0:7af58844bc21 | 123 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 124 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 125 | lcd.printf("Tbi:%d",Tp); |
juniorACA | 0:7af58844bc21 | 126 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 127 | lcd.printf("Nbi:%d",num_bits); |
juniorACA | 0:7af58844bc21 | 128 | wait(3); |
juniorACA | 0:7af58844bc21 | 129 | Tecla=0; |
juniorACA | 0:7af58844bc21 | 130 | |
juniorACA | 0:7af58844bc21 | 131 | } |
juniorACA | 0:7af58844bc21 | 132 | if(Tecla==T3) |
juniorACA | 0:7af58844bc21 | 133 | { |
juniorACA | 0:7af58844bc21 | 134 | Fi=(Dd)*100; |
juniorACA | 0:7af58844bc21 | 135 | pp=(1/Fi); |
juniorACA | 0:7af58844bc21 | 136 | sonido.period(pp); |
juniorACA | 0:7af58844bc21 | 137 | sonido.write(0.1); |
juniorACA | 0:7af58844bc21 | 138 | wait(0.1); |
juniorACA | 0:7af58844bc21 | 139 | sonido.write(0); |
juniorACA | 0:7af58844bc21 | 140 | wait(0.1); |
juniorACA | 0:7af58844bc21 | 141 | led3=!led3; |
juniorACA | 0:7af58844bc21 | 142 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 143 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 144 | lcd.printf("Boton 6"); |
juniorACA | 0:7af58844bc21 | 145 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 146 | lcd.printf("Codigo=%d",Tecla); |
juniorACA | 0:7af58844bc21 | 147 | wait(3); |
juniorACA | 0:7af58844bc21 | 148 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 149 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 150 | lcd.printf("HL:%d",head_L); |
juniorACA | 0:7af58844bc21 | 151 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 152 | lcd.printf("HH:%d",head_H); |
juniorACA | 0:7af58844bc21 | 153 | wait(3); |
juniorACA | 0:7af58844bc21 | 154 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 155 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 156 | lcd.printf("Tbi:%d",Tp); |
juniorACA | 0:7af58844bc21 | 157 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 158 | lcd.printf("Nbi:%d",num_bits); |
juniorACA | 0:7af58844bc21 | 159 | wait(3); |
juniorACA | 0:7af58844bc21 | 160 | Tecla=0; |
juniorACA | 0:7af58844bc21 | 161 | |
juniorACA | 0:7af58844bc21 | 162 | } |
juniorACA | 0:7af58844bc21 | 163 | |
juniorACA | 0:7af58844bc21 | 164 | if ((Tecla!=T3)&&(Tecla!=T2)&&(Tecla!=T1)&&(Tecla!=0)){ |
juniorACA | 0:7af58844bc21 | 165 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 166 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 167 | lcd.printf("Boton no Valido"); |
juniorACA | 0:7af58844bc21 | 168 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 169 | lcd.printf("Codigo=%d",Tecla); |
juniorACA | 0:7af58844bc21 | 170 | wait(3); |
juniorACA | 0:7af58844bc21 | 171 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 172 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 173 | lcd.printf("HL:%d",head_L); |
juniorACA | 0:7af58844bc21 | 174 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 175 | lcd.printf("HH:%d",head_H); |
juniorACA | 0:7af58844bc21 | 176 | wait(3); |
juniorACA | 0:7af58844bc21 | 177 | lcd.cls(); |
juniorACA | 0:7af58844bc21 | 178 | lcd.locate(4,0); |
juniorACA | 0:7af58844bc21 | 179 | lcd.printf("Tbi:%d",Tp); |
juniorACA | 0:7af58844bc21 | 180 | lcd.locate(4,1); |
juniorACA | 0:7af58844bc21 | 181 | lcd.printf("Nbi:%d",num_bits); |
juniorACA | 0:7af58844bc21 | 182 | wait(3); |
juniorACA | 0:7af58844bc21 | 183 | Tecla=0; |
juniorACA | 0:7af58844bc21 | 184 | } |
juniorACA | 0:7af58844bc21 | 185 | } |
juniorACA | 0:7af58844bc21 | 186 | } |