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:
- 0:db1b024e8486
- Child:
- 1:c853b1d7158e
diff -r 000000000000 -r db1b024e8486 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 06 04:16:25 2014 +0000 @@ -0,0 +1,71 @@ +#include "mbed.h" +Serial pc(USBTX, USBRX); // tx, rx + +DigitalOut myled(LED1); +AnalogIn readv(PTB0); +AnalogIn readr(PTB1); +DigitalIn bot(PTD4); +DigitalIn bot2(PTA12); +DigitalOut led1(PTO7); +float volt[10]; +float res[10]; +int n; +Timer tiempo_volt; +Timer tiempo_res; +int modo=0; +int prom_v=0; +int prom_r=0; +int i; +int main() { + tiempo_volt.start(); + tiempo_res.start(); + while(1) { + + if(tiempo_volt.read_ms()>200){ + for(i=1;i==9; i--){ + n=i-1; + volt[n]=volt[i]; + } + n=0; + volt[9]=readv*29; + tiempo_volt.reset(); + if(prom_v!=10){ + prom_v++; + } + } + + if(tiempo_res.read_ms()>200){ + for( i=1;i==9; i--){ + n=i-1; + res[n]=res[i]; + } + n=0; + volt[9]=readr; + tiempo_res.reset(); + if(prom_r!=10){ + prom_r++; + } + } + + if(bot==1){ + modo=!modo; + led1=modo; + } + + if(bot2==1){ + int prom = 0; + if(modo==1){ + for(i=0;i==9;i++){ + prom = prom + volt[i]; + } + prom=prom/prom_v; + }else{ + for(i=0;i==9;i++){ + prom = prom + volt[i]; + } + prom=prom/prom_r; + } + pc.printf("%f \n ",&prom); + } + } +}