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:
- 1:83a13087626e
- Parent:
- 0:626906048498
- Child:
- 2:a18f03867915
--- a/main.cpp Fri Feb 19 13:15:55 2016 +0000
+++ b/main.cpp Fri Feb 19 14:38:05 2016 +0000
@@ -1,12 +1,39 @@
#include "mbed.h"
-
-DigitalOut myled(LED1);
-
-int main() {
- while(1) {
- myled = 1;
- wait(0.2);
- myled = 0;
- wait(0.2);
- }
-}
+Serial serialpc( USBTX,USBRX);
+InterruptIn Echo(D8);
+DigitalOut Trigg(D9);
+Timer timer;
+float dist=0;
+DigitalOut led(LED2);
+ void start(){
+ timer.reset();
+ timer.start();
+ }
+
+ void stop(){
+ timer.stop();
+ dist=timer.read_us();
+ }
+
+ int main(){
+ Echo.rise(&start);
+ Echo.fall(&stop);
+ Trigg=0;
+
+ while(1){
+ dist=0;
+ Trigg=1;
+ wait_us(10);
+ Trigg=0;
+ while(dist==0){
+ wait_us(1);
+
+ }
+
+ dist=dist/58.0;
+
+
+ serialpc.printf("distancia %f cm\n",dist);
+ wait(.2);
+ }
+ }
\ No newline at end of file