![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Control de la intensidad luminosa de un led con control remoto Samsung
main.cpp@1:e8170a2014a1, 2015-11-23 (annotated)
- Committer:
- Meli
- Date:
- Mon Nov 23 08:18:03 2015 +0000
- Revision:
- 1:e8170a2014a1
- Parent:
- 0:9727a355c3cd
Control de la intensidad luminosa de un led con control remoto Samsung
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Meli | 0:9727a355c3cd | 1 | #include "mbed.h" |
Meli | 0:9727a355c3cd | 2 | #include <Pulse1.h> |
Meli | 1:e8170a2014a1 | 3 | |
Meli | 0:9727a355c3cd | 4 | //control remoto |
Meli | 0:9727a355c3cd | 5 | PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo |
Meli | 0:9727a355c3cd | 6 | Serial pc(USBTX, USBRX); |
Meli | 0:9727a355c3cd | 7 | //DigitalOut ledazul(LED1); |
Meli | 0:9727a355c3cd | 8 | //DigitalOut led2(LED2); |
Meli | 0:9727a355c3cd | 9 | PwmOut ledazul(LED1); |
Meli | 1:e8170a2014a1 | 10 | |
Meli | 1:e8170a2014a1 | 11 | |
Meli | 0:9727a355c3cd | 12 | int header =0; //tiempo de cabecera pulso abajo |
Meli | 0:9727a355c3cd | 13 | const int head_H = 9900; //+10% medida con osciloscopio en microsegundos 9000 |
Meli | 0:9727a355c3cd | 14 | const int head_L = 4983;//-10% medida con osciloscopio 4530 |
Meli | 0:9727a355c3cd | 15 | int i=0, u=0, y=0; |
Meli | 0:9727a355c3cd | 16 | const int T_alto=1630;//ponga su tiempo de la prueba |
Meli | 0:9727a355c3cd | 17 | const int T_bajo=600;//ponga su tiempo de la prueba |
Meli | 0:9727a355c3cd | 18 | const int num_bits = 42;//ponga su numero de bits |
Meli | 0:9727a355c3cd | 19 | int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos |
Meli | 0:9727a355c3cd | 20 | int dato,prender,aumentar,disminuir,j=0; // tiempo de cada dato que se lee |
Meli | 0:9727a355c3cd | 21 | int var[42]; |
Meli | 1:e8170a2014a1 | 22 | |
Meli | 1:e8170a2014a1 | 23 | |
Meli | 0:9727a355c3cd | 24 | float brightness=0; |
Meli | 0:9727a355c3cd | 25 | float brightness1=1; |
Meli | 1:e8170a2014a1 | 26 | |
Meli | 0:9727a355c3cd | 27 | int main(){ |
Meli | 0:9727a355c3cd | 28 | ledazul = 0; |
Meli | 0:9727a355c3cd | 29 | |
Meli | 0:9727a355c3cd | 30 | while(1){ |
Meli | 0:9727a355c3cd | 31 | ini1: fflush( stdin ); |
Meli | 0:9727a355c3cd | 32 | header=0; |
Meli | 0:9727a355c3cd | 33 | |
Meli | 0:9727a355c3cd | 34 | header = irda.read_low_us(); //funcion para leer un pulso de caida o bajo en header |
Meli | 0:9727a355c3cd | 35 | if (header > head_L && header < head_H) goto seguir;//verificar que este en la tolerancia +-20% |
Meli | 0:9727a355c3cd | 36 | else goto ini1; |
Meli | 0:9727a355c3cd | 37 | |
Meli | 0:9727a355c3cd | 38 | seguir: |
Meli | 0:9727a355c3cd | 39 | //leo los datos de la trama y se meten a un arreglo |
Meli | 0:9727a355c3cd | 40 | wait_us(4500);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO |
Meli | 0:9727a355c3cd | 41 | |
Meli | 0:9727a355c3cd | 42 | for(i=0;i<(num_bits-1);++i){ // POR OSCILOSCOPIO se determina que llegan (num_bits),datos |
Meli | 0:9727a355c3cd | 43 | dato = irda.read_high_us(); //leer un bit de datos que es pulso arriba en este control |
Meli | 0:9727a355c3cd | 44 | num[i]=dato; |
Meli | 0:9727a355c3cd | 45 | wait_us(430); |
Meli | 0:9727a355c3cd | 46 | |
Meli | 0:9727a355c3cd | 47 | } |
Meli | 0:9727a355c3cd | 48 | wait(0.5); //espero un poquito luego de leer todo el arreglo y ponerlo en pantalla |
Meli | 0:9727a355c3cd | 49 | //pc.printf(",%d",header); |
Meli | 0:9727a355c3cd | 50 | for(i=0;i<(num_bits-1);++i){ |
Meli | 0:9727a355c3cd | 51 | //pc.printf(",%d",num[i]); |
Meli | 0:9727a355c3cd | 52 | } |
Meli | 0:9727a355c3cd | 53 | wait(0.1); //espero e imprimo en binario |
Meli | 0:9727a355c3cd | 54 | pc.printf("\n\n"); |
Meli | 0:9727a355c3cd | 55 | |
Meli | 0:9727a355c3cd | 56 | for(i=0;i<(num_bits-1);++i){ |
Meli | 0:9727a355c3cd | 57 | if(num[i] > ((T_alto+T_bajo)/2)) { |
Meli | 0:9727a355c3cd | 58 | pc.printf("1"); |
Meli | 0:9727a355c3cd | 59 | var[i]=1; |
Meli | 0:9727a355c3cd | 60 | } |
Meli | 0:9727a355c3cd | 61 | |
Meli | 0:9727a355c3cd | 62 | else { |
Meli | 0:9727a355c3cd | 63 | pc.printf("0"); |
Meli | 0:9727a355c3cd | 64 | var[i]=0; |
Meli | 0:9727a355c3cd | 65 | } |
Meli | 0:9727a355c3cd | 66 | } |
Meli | 0:9727a355c3cd | 67 | |
Meli | 0:9727a355c3cd | 68 | int power[] = {0,1,1,0,0,1,1,0,0,0,0,0,0,1,0,0,1,1,0,0,1,1,1,1,1,1,1,0,0,0,1,0,0,1,0,1,1,1,0,1,1}; |
Meli | 0:9727a355c3cd | 69 | int mas[] = {0,1,1,0,0,1,1,0,0,0,0,0,0,1,0,0,1,1,0,0,1,1,1,1,1,1,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1}; |
Meli | 0:9727a355c3cd | 70 | int menos[] = {0,1,1,0,0,1,1,0,0,0,0,0,0,1,0,0,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1}; |
Meli | 0:9727a355c3cd | 71 | |
Meli | 0:9727a355c3cd | 72 | prender=0; |
Meli | 0:9727a355c3cd | 73 | aumentar=0; |
Meli | 0:9727a355c3cd | 74 | disminuir=0; |
Meli | 0:9727a355c3cd | 75 | |
Meli | 0:9727a355c3cd | 76 | for(i=0;i<=(num_bits-1);i++){ |
Meli | 0:9727a355c3cd | 77 | if(var[i]==power[i]){ |
Meli | 0:9727a355c3cd | 78 | prender++; |
Meli | 0:9727a355c3cd | 79 | } |
Meli | 0:9727a355c3cd | 80 | if(var[i]==mas[i]){ |
Meli | 0:9727a355c3cd | 81 | aumentar++; |
Meli | 0:9727a355c3cd | 82 | } |
Meli | 0:9727a355c3cd | 83 | if(var[i]==menos[i]){ |
Meli | 0:9727a355c3cd | 84 | |
Meli | 0:9727a355c3cd | 85 | disminuir++; |
Meli | 0:9727a355c3cd | 86 | } |
Meli | 0:9727a355c3cd | 87 | } |
Meli | 0:9727a355c3cd | 88 | |
Meli | 0:9727a355c3cd | 89 | if (ledazul==0 && prender==42){ |
Meli | 0:9727a355c3cd | 90 | ledazul=1; |
Meli | 0:9727a355c3cd | 91 | } |
Meli | 0:9727a355c3cd | 92 | else if(ledazul==1 && prender==42){ |
Meli | 0:9727a355c3cd | 93 | ledazul=0; |
Meli | 0:9727a355c3cd | 94 | } |
Meli | 0:9727a355c3cd | 95 | |
Meli | 0:9727a355c3cd | 96 | |
Meli | 0:9727a355c3cd | 97 | if(aumentar==42) { |
Meli | 0:9727a355c3cd | 98 | if (brightness < 1){ |
Meli | 1:e8170a2014a1 | 99 | brightness += 0.2; |
Meli | 0:9727a355c3cd | 100 | } |
Meli | 0:9727a355c3cd | 101 | else { |
Meli | 0:9727a355c3cd | 102 | brightness = 1; |
Meli | 0:9727a355c3cd | 103 | } |
Meli | 0:9727a355c3cd | 104 | |
Meli | 0:9727a355c3cd | 105 | ledazul = brightness; |
Meli | 0:9727a355c3cd | 106 | } |
Meli | 0:9727a355c3cd | 107 | |
Meli | 0:9727a355c3cd | 108 | if(disminuir==42) { |
Meli | 1:e8170a2014a1 | 109 | if ( 1< brightness1){ |
Meli | 1:e8170a2014a1 | 110 | brightness1 -= 0.1; |
Meli | 0:9727a355c3cd | 111 | } |
Meli | 0:9727a355c3cd | 112 | else { |
Meli | 1:e8170a2014a1 | 113 | brightness1 = 1; |
Meli | 1:e8170a2014a1 | 114 | } |
Meli | 0:9727a355c3cd | 115 | |
Meli | 1:e8170a2014a1 | 116 | ledazul = brightness1; |
Meli | 1:e8170a2014a1 | 117 | } |
Meli | 1:e8170a2014a1 | 118 | |
Meli | 0:9727a355c3cd | 119 | |
Meli | 0:9727a355c3cd | 120 | |
Meli | 1:e8170a2014a1 | 121 | }} |