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.
Diff: main.cpp
- Revision:
- 2:a0c5943abc7d
- Parent:
- 1:c853b1d7158e
--- a/main.cpp Thu Mar 13 02:42:52 2014 +0000 +++ b/main.cpp Thu Mar 13 03:28:10 2014 +0000 @@ -1,41 +1,47 @@ #include "mbed.h" +/*Inicializacion de objetos*/ + Serial pc(USBTX, USBRX); // tx, rx // G F A B E D C -BusOut display1(PTD4,PTA12,PTA4,PTA5,PTC8,PTC9,PTA13); +BusOut dis_1(PTD4,PTA12,PTA4,PTA5,PTC8,PTC9,PTA13); // G F A B E D C -BusOut display2(PTD4,PTA12,PTA4,PTA5,PTC8,PTC9,PTA13); - +BusOut dis_2(PTD4,PTA12,PTA4,PTA5,PTC8,PTC9,PTA13); AnalogIn readv(PTB0); AnalogIn readr(PTB1); DigitalIn bot(PTE29); DigitalIn bot2(PTE23); DigitalOut led1(PTC7); -float volt[10]; -float res[10]; -int n; +#define Num_datos 10 Timer tiempo_volt; Timer tiempo_res; +/*Declaracion de variables*/ +float volt[Num_datos]; +float res[Num_datos]; +int n; int modo=0; int prom_v=0; int prom_r=0; int i; int entero; int decimal; +/*Declaracion de variables*/ void desplegar_ero(int entero); void desplegar_do(int decimal); + +/*PROGRAMA PRINCIPAL*/ int main() { - //tiempo_volt.start(); - //tiempo_res.start(); + tiempo_volt.start(); + tiempo_res.start(); while(1) { - - led1=1; + led1=1; wait(0.2); led1=0; wait(0.2); - if(tiempo_volt.read_ms()>200){ - for(i=1;i<=9; i--){ + /*Se realizan n lecturas de voltaje por ciclo hasta llegar a 10*/ + if(tiempo_volt.read_ms()>500){ + for(i=1;i<=9; i++){ n=i-1; volt[n]=volt[i]; } @@ -47,8 +53,9 @@ } } - if(tiempo_res.read_ms()>200){ - for( i=1;i==9; i--){ + /*Se realizan n lecturas de resistencia por ciclo hasta llegar a 10*/ + if(tiempo_res.read_ms()>500){ + for( i=1;i<=9; i++){ n=i-1; res[n]=res[i]; } @@ -59,35 +66,37 @@ prom_r++; } } + /*elige lo que va a mostar, si resistencia o voltaje*/ if(bot==0){ modo=!modo; led1=modo; } - + /*Cuando el boton es presionado, a depender, nos realizara un promedio de los valores*/ if(bot2==0){ int prom = 0; if(modo==1){ for(i=0;i<=9;i++){ - prom = prom + volt[i]; + prom = prom + volt[i]; } - prom=prom/prom_v; + prom=prom/prom_v; }else{ for(i=0;i==9;i++){ - prom = prom + res[i]; + prom = prom + res[i]; } - prom=prom/prom_r; + prom=prom/prom_r; } - pc.printf("%f \n ",&prom); - entero = (int)prom/10; - decimal = prom%10; - desplegar_ero(entero); - desplegar_do(decimal); + //llamaos las funciones para imprimir los valores + pc.printf("%f \n ",&prom); + entero = (int)prom/10; + decimal = prom%10; + desplegar_ero(entero); + desplegar_do(decimal); } } } - +//Funciones para encender los displays void desplegar_ero(int entero){ switch(entero){ case 0: