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.
Fork of irda_V_aula by
Revision 4:790b7fce49bd, committed 2015-11-06
- Comitter:
- GermanD
- Date:
- Fri Nov 06 21:01:23 2015 +0000
- Parent:
- 3:82bebaf2a06a
- Commit message:
- C?digo para prender y apagar un pwm y controlarlo con las teclas de un control de tv.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 82bebaf2a06a -r 790b7fce49bd main.cpp
--- a/main.cpp Thu May 08 00:38:39 2014 +0000
+++ b/main.cpp Fri Nov 06 21:01:23 2015 +0000
@@ -1,25 +1,35 @@
#include "mbed.h"
#include <Pulse1.h>
+#include <string.h>
//control remoto videobeam aula
PulseInOut irda(PTD5);// en este puerto se pone el sensor infrarrojo
Serial pc(USBTX, USBRX);
-DigitalOut led(LED1);
-DigitalOut led2(LED2);
+DigitalOut led(LED1); // indica que oprimí un botón
+DigitalOut g1(PTD0); // salida para prender y apagar
+PwmOut p1(PTA13); // salida para PWM
+
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 head_H = 2400+2400*0.1; //+10% medida con osciloscopio en microsegundos
+const int head_L = 2400-2400*0.1;//-10% medida con osciloscopio
int i=0;
-const int T_alto=1630;//ponga su tiempo de la prueba
-const int T_bajo=533;//ponga su tiempo de la prueba
-const int num_bits = 64;//ponga su numero de bits
+const int T_alto=586;//ponga su tiempo de la prueba
+const int T_bajo=1243;//ponga su tiempo de la prueba
+const int num_bits = 13;//ponga su numero de bits
int num[num_bits];//cadena para almacenar todos los tiempos que conforman los bits de datos
-int dato; // tiempo de cada dato que se lee
+int dato,prender,subir,bajar,rsubir,rbajar,conts,contb; // tiempo de cada dato que se lee
+int bot[12]; // variable para guardar la trama del botón
+
int main(){
+p1=0;
+rsubir=0;
+rbajar=0;
+conts=0; // contador para subir rapido
+contb=0; // contador para bajar rapido
+
while(1){
ini1: fflush( stdin );
header=0;
- led2=1;
led=1;
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%
@@ -27,10 +37,10 @@
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;
+ wait_us(333);// ES EL TIEMPO DE HEADER QUE NO SE Lee O EL ALTO
+ led=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
+ dato = irda.read_low_us(); //leer un bit de datos que es pulso arriba en este control
num[i]=dato;
wait_us(300);
}
@@ -39,11 +49,80 @@
for(i=0;i<(num_bits-1);++i){
pc.printf(",%d",num[i]);
}
- wait(0.1); //espero e imprimo en binario
+ //wait(0.1); //espero e imprimo en binario
pc.printf("\n\n");
for(i=0;i<(num_bits-1);++i){
- if(num[i] > ((T_alto+T_bajo)/2)) pc.printf("1");
- else pc.printf("0");
+ if(num[i] > ((T_alto+T_bajo)/2)){
+
+ pc.printf("1");
+ bot[i] = 1;
+ }
+
+ else {
+ pc.printf("0");
+ bot[i] = 0;
}
}
+
+ int sol[]={1,0,1,0,0,1,1,1,0,0,0,0};
+ int arriba[]={0,0,1,0,1,1,1,1,0,0,0,0};
+ int abajo[]={1,0,1,0,1,1,1,1,0,0,0,0};
+ prender=0;
+ subir=0;
+ bajar=0;
+
+ // comparo lo que me entra con el vector del botón
+ for(i=0;i<=(num_bits-1);i++){
+ if(bot[i]==sol[i]){
+
+ prender++;
+ }
+ if(bot[i]==arriba[i]){
+
+ subir++;
+ }
+ if(bot[i]==abajo[i]){
+
+ bajar++;
+ }
+
+
+ }
+
+ // para prender y apagar
+ if (g1==0 && prender==12) g1=1;
+ else if (g1==1 && prender==12) g1=0;
+
+
+ // para subir y bajar
+ if (subir==12 && p1<1){
+ if (p1>=1) p1=1;
+ p1=p1+0.02;
+ rsubir=1;
+ rbajar=0;
+ conts = conts++;
+ if (conts>=3) conts=3;
+ }
+
+ if (bajar==12 && 0<p1){
+ if (p1<=0) p1=0;
+ p1=p1-0.02;
+ rsubir=0;
+ rbajar=1;
+ contb=contb++;
+ if (contb>=3) contb=3;
+ }
+
+
+ // para subir y bajar mas rápido
+ if(conts==3 && rsubir==1){
+ if (p1>=1) p1=1;
+ p1=p1+0.08;
+ }
+ if(contb==3 && rbajar==1){
+ if (p1<=0) p1=0;
+ p1=p1-0.08;
+ }
+
+ }
}
\ No newline at end of file
diff -r 82bebaf2a06a -r 790b7fce49bd mbed.bld --- a/mbed.bld Thu May 08 00:38:39 2014 +0000 +++ b/mbed.bld Fri Nov 06 21:01:23 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/f37f3b9c9f0b \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11 \ No newline at end of file
