Tarea6_ModoInfrarrojo, en el cual con tres teclas, enciendo tres leds en modo toogle.
Dependencies: Pulse1 TextLCD mbed
main.cpp@0:a869387ac0f8, 2014-05-14 (annotated)
- Committer:
- Jesse
- Date:
- Wed May 14 15:35:31 2014 +0000
- Revision:
- 0:a869387ac0f8
Tarea 6_ModoInfrarrojo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jesse | 0:a869387ac0f8 | 1 | //Michelle Maceas Henao |
Jesse | 0:a869387ac0f8 | 2 | //Jesse Mauricio Beltran Soto |
Jesse | 0:a869387ac0f8 | 3 | |
Jesse | 0:a869387ac0f8 | 4 | #include "mbed.h" |
Jesse | 0:a869387ac0f8 | 5 | #include <Pulse1.h> |
Jesse | 0:a869387ac0f8 | 6 | #include "TextLCD.h" |
Jesse | 0:a869387ac0f8 | 7 | |
Jesse | 0:a869387ac0f8 | 8 | |
Jesse | 0:a869387ac0f8 | 9 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7#include "TextLCD.h" |
Jesse | 0:a869387ac0f8 | 10 | //control remoto videobeam aula |
Jesse | 0:a869387ac0f8 | 11 | PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo |
Jesse | 0:a869387ac0f8 | 12 | Serial pc(USBTX, USBRX); |
Jesse | 0:a869387ac0f8 | 13 | DigitalOut led(LED1); |
Jesse | 0:a869387ac0f8 | 14 | DigitalOut led2(LED2); |
Jesse | 0:a869387ac0f8 | 15 | DigitalOut led3(LED3); |
Jesse | 0:a869387ac0f8 | 16 | int header =0; //tiempo de cabecera pulso abajo |
Jesse | 0:a869387ac0f8 | 17 | const int head_H = 9120; //+10% medida con osciloscopio en microsegundos |
Jesse | 0:a869387ac0f8 | 18 | const int head_L = 8939;//-10% medida con osciloscopio |
Jesse | 0:a869387ac0f8 | 19 | const int Tp=300; |
Jesse | 0:a869387ac0f8 | 20 | int i=0; |
Jesse | 0:a869387ac0f8 | 21 | const int T_alto=1570;//1630;//ponga su tiempo de la prueba |
Jesse | 0:a869387ac0f8 | 22 | const int T_bajo=467;//533;//ponga su tiempo de la prueba |
Jesse | 0:a869387ac0f8 | 23 | const int num_bits = 32;//ponga su numero de bits |
Jesse | 0:a869387ac0f8 | 24 | int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos |
Jesse | 0:a869387ac0f8 | 25 | int num2[num_bits];//Cadena para almacenar datos |
Jesse | 0:a869387ac0f8 | 26 | //int numA[num_bits]={1,0,0,0}; |
Jesse | 0:a869387ac0f8 | 27 | int Num=0; |
Jesse | 0:a869387ac0f8 | 28 | const int A=170; |
Jesse | 0:a869387ac0f8 | 29 | const int B=205; |
Jesse | 0:a869387ac0f8 | 30 | const int C=200; |
Jesse | 0:a869387ac0f8 | 31 | int C1=0,flag1=0; |
Jesse | 0:a869387ac0f8 | 32 | int C2=0,flag2=0; |
Jesse | 0:a869387ac0f8 | 33 | int C3=0,flag3=0; |
Jesse | 0:a869387ac0f8 | 34 | int flagg=0; |
Jesse | 0:a869387ac0f8 | 35 | |
Jesse | 0:a869387ac0f8 | 36 | int dato; // tiempo de cada dato que se lee |
Jesse | 0:a869387ac0f8 | 37 | |
Jesse | 0:a869387ac0f8 | 38 | int main() |
Jesse | 0:a869387ac0f8 | 39 | { |
Jesse | 0:a869387ac0f8 | 40 | led2=1; //Apago los leds. |
Jesse | 0:a869387ac0f8 | 41 | led=1; |
Jesse | 0:a869387ac0f8 | 42 | led3=1; |
Jesse | 0:a869387ac0f8 | 43 | |
Jesse | 0:a869387ac0f8 | 44 | |
Jesse | 0:a869387ac0f8 | 45 | |
Jesse | 0:a869387ac0f8 | 46 | |
Jesse | 0:a869387ac0f8 | 47 | while(1) |
Jesse | 0:a869387ac0f8 | 48 | { |
Jesse | 0:a869387ac0f8 | 49 | |
Jesse | 0:a869387ac0f8 | 50 | if(flagg==0) |
Jesse | 0:a869387ac0f8 | 51 | { |
Jesse | 0:a869387ac0f8 | 52 | lcd.cls(); |
Jesse | 0:a869387ac0f8 | 53 | lcd.locate(0,0); |
Jesse | 0:a869387ac0f8 | 54 | lcd.printf("HH:%d",head_H); |
Jesse | 0:a869387ac0f8 | 55 | lcd.locate(8,0); |
Jesse | 0:a869387ac0f8 | 56 | lcd.printf("Tby:%d",Tp); |
Jesse | 0:a869387ac0f8 | 57 | lcd.locate(0,1); |
Jesse | 0:a869387ac0f8 | 58 | lcd.printf("HL:%d",head_L); |
Jesse | 0:a869387ac0f8 | 59 | lcd.locate(8,1); |
Jesse | 0:a869387ac0f8 | 60 | lcd.printf("Nby:%d",num_bits); |
Jesse | 0:a869387ac0f8 | 61 | } |
Jesse | 0:a869387ac0f8 | 62 | ini1: fflush( stdin ); |
Jesse | 0:a869387ac0f8 | 63 | header=0; |
Jesse | 0:a869387ac0f8 | 64 | header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header |
Jesse | 0:a869387ac0f8 | 65 | if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% |
Jesse | 0:a869387ac0f8 | 66 | else goto ini1; |
Jesse | 0:a869387ac0f8 | 67 | |
Jesse | 0:a869387ac0f8 | 68 | seguir: |
Jesse | 0:a869387ac0f8 | 69 | //leo los datos de la trama y se meten a un arreglo |
Jesse | 0:a869387ac0f8 | 70 | wait_us(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO |
Jesse | 0:a869387ac0f8 | 71 | //led2=0; |
Jesse | 0:a869387ac0f8 | 72 | lcd.cls(); |
Jesse | 0:a869387ac0f8 | 73 | Num=0; |
Jesse | 0:a869387ac0f8 | 74 | for(i=0;i<(num_bits-1);++i) |
Jesse | 0:a869387ac0f8 | 75 | { // POR OSCILOSCOPIO se determina que llegan (num_bits),datos |
Jesse | 0:a869387ac0f8 | 76 | dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control |
Jesse | 0:a869387ac0f8 | 77 | num[i]=dato; |
Jesse | 0:a869387ac0f8 | 78 | wait_us(Tp); |
Jesse | 0:a869387ac0f8 | 79 | } |
Jesse | 0:a869387ac0f8 | 80 | wait(0.3); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla |
Jesse | 0:a869387ac0f8 | 81 | pc.printf(",%d",header); |
Jesse | 0:a869387ac0f8 | 82 | for(i=0;i<(num_bits-1);++i) |
Jesse | 0:a869387ac0f8 | 83 | { |
Jesse | 0:a869387ac0f8 | 84 | pc.printf(",%d",num[i]); |
Jesse | 0:a869387ac0f8 | 85 | } |
Jesse | 0:a869387ac0f8 | 86 | wait(0.1); //espero e imprimo en binario |
Jesse | 0:a869387ac0f8 | 87 | pc.printf("\n\n"); |
Jesse | 0:a869387ac0f8 | 88 | for(i=0;i<(num_bits-1);++i) |
Jesse | 0:a869387ac0f8 | 89 | { |
Jesse | 0:a869387ac0f8 | 90 | |
Jesse | 0:a869387ac0f8 | 91 | if(num[i] > ((T_alto+T_bajo)/2)) |
Jesse | 0:a869387ac0f8 | 92 | { |
Jesse | 0:a869387ac0f8 | 93 | pc.printf("1"); |
Jesse | 0:a869387ac0f8 | 94 | num2[i]=1; |
Jesse | 0:a869387ac0f8 | 95 | if(i>17) |
Jesse | 0:a869387ac0f8 | 96 | { |
Jesse | 0:a869387ac0f8 | 97 | Num=Num+1*(2^(i)); |
Jesse | 0:a869387ac0f8 | 98 | } |
Jesse | 0:a869387ac0f8 | 99 | } |
Jesse | 0:a869387ac0f8 | 100 | else |
Jesse | 0:a869387ac0f8 | 101 | { |
Jesse | 0:a869387ac0f8 | 102 | pc.printf("0"); |
Jesse | 0:a869387ac0f8 | 103 | } |
Jesse | 0:a869387ac0f8 | 104 | |
Jesse | 0:a869387ac0f8 | 105 | } |
Jesse | 0:a869387ac0f8 | 106 | |
Jesse | 0:a869387ac0f8 | 107 | if(Num==A) |
Jesse | 0:a869387ac0f8 | 108 | { |
Jesse | 0:a869387ac0f8 | 109 | flagg=1; |
Jesse | 0:a869387ac0f8 | 110 | lcd.cls(); |
Jesse | 0:a869387ac0f8 | 111 | lcd.printf(" LED ROJO"); |
Jesse | 0:a869387ac0f8 | 112 | lcd.locate(0,1); |
Jesse | 0:a869387ac0f8 | 113 | lcd.printf(" [Decimal]:%d",Num); |
Jesse | 0:a869387ac0f8 | 114 | led=0; |
Jesse | 0:a869387ac0f8 | 115 | C1=C1+1; |
Jesse | 0:a869387ac0f8 | 116 | Num=0; |
Jesse | 0:a869387ac0f8 | 117 | } |
Jesse | 0:a869387ac0f8 | 118 | if(Num==B) |
Jesse | 0:a869387ac0f8 | 119 | { |
Jesse | 0:a869387ac0f8 | 120 | flagg=1; |
Jesse | 0:a869387ac0f8 | 121 | lcd.cls(); |
Jesse | 0:a869387ac0f8 | 122 | lcd.printf(" LED VERDE"); |
Jesse | 0:a869387ac0f8 | 123 | lcd.locate(0,1); |
Jesse | 0:a869387ac0f8 | 124 | lcd.printf(" [Decimal]:%d",Num); |
Jesse | 0:a869387ac0f8 | 125 | Num=0; |
Jesse | 0:a869387ac0f8 | 126 | led2=0; |
Jesse | 0:a869387ac0f8 | 127 | C2=C2+1; |
Jesse | 0:a869387ac0f8 | 128 | Num=0; |
Jesse | 0:a869387ac0f8 | 129 | } |
Jesse | 0:a869387ac0f8 | 130 | if(Num==C) |
Jesse | 0:a869387ac0f8 | 131 | { |
Jesse | 0:a869387ac0f8 | 132 | flagg=1; |
Jesse | 0:a869387ac0f8 | 133 | lcd.cls(); |
Jesse | 0:a869387ac0f8 | 134 | lcd.printf(" LED AZUL"); |
Jesse | 0:a869387ac0f8 | 135 | lcd.locate(0,1); |
Jesse | 0:a869387ac0f8 | 136 | lcd.printf(" [Decimal]:%d",Num); |
Jesse | 0:a869387ac0f8 | 137 | led3=0; |
Jesse | 0:a869387ac0f8 | 138 | C3=C3+1; |
Jesse | 0:a869387ac0f8 | 139 | Num=0; |
Jesse | 0:a869387ac0f8 | 140 | } |
Jesse | 0:a869387ac0f8 | 141 | if(C1==2) |
Jesse | 0:a869387ac0f8 | 142 | { |
Jesse | 0:a869387ac0f8 | 143 | led=1; |
Jesse | 0:a869387ac0f8 | 144 | C1=0; |
Jesse | 0:a869387ac0f8 | 145 | } |
Jesse | 0:a869387ac0f8 | 146 | if(C2==2) |
Jesse | 0:a869387ac0f8 | 147 | { |
Jesse | 0:a869387ac0f8 | 148 | led2=1; |
Jesse | 0:a869387ac0f8 | 149 | C2=0; |
Jesse | 0:a869387ac0f8 | 150 | } |
Jesse | 0:a869387ac0f8 | 151 | if(C3==2) |
Jesse | 0:a869387ac0f8 | 152 | { |
Jesse | 0:a869387ac0f8 | 153 | led3=1; |
Jesse | 0:a869387ac0f8 | 154 | C3=0; |
Jesse | 0:a869387ac0f8 | 155 | } |
Jesse | 0:a869387ac0f8 | 156 | if((C1==0)&&(C2==0)&&(C3==0)) |
Jesse | 0:a869387ac0f8 | 157 | { |
Jesse | 0:a869387ac0f8 | 158 | flagg=0; |
Jesse | 0:a869387ac0f8 | 159 | } |
Jesse | 0:a869387ac0f8 | 160 | } |
Jesse | 0:a869387ac0f8 | 161 | } |