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.
main.cpp@1:83a13087626e, 2016-02-19 (annotated)
- Committer:
- joseortega
- Date:
- Fri Feb 19 14:38:05 2016 +0000
- Revision:
- 1:83a13087626e
- Parent:
- 0:626906048498
- Child:
- 2:a18f03867915
sensor ultrasonido
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| joseortega | 0:626906048498 | 1 | #include "mbed.h" | 
| joseortega | 1:83a13087626e | 2 | Serial serialpc( USBTX,USBRX); | 
| joseortega | 1:83a13087626e | 3 | InterruptIn Echo(D8); | 
| joseortega | 1:83a13087626e | 4 | DigitalOut Trigg(D9); | 
| joseortega | 1:83a13087626e | 5 | Timer timer; | 
| joseortega | 1:83a13087626e | 6 | float dist=0; | 
| joseortega | 1:83a13087626e | 7 | DigitalOut led(LED2); | 
| joseortega | 1:83a13087626e | 8 | void start(){ | 
| joseortega | 1:83a13087626e | 9 | timer.reset(); | 
| joseortega | 1:83a13087626e | 10 | timer.start(); | 
| joseortega | 1:83a13087626e | 11 | } | 
| joseortega | 1:83a13087626e | 12 | |
| joseortega | 1:83a13087626e | 13 | void stop(){ | 
| joseortega | 1:83a13087626e | 14 | timer.stop(); | 
| joseortega | 1:83a13087626e | 15 | dist=timer.read_us(); | 
| joseortega | 1:83a13087626e | 16 | } | 
| joseortega | 1:83a13087626e | 17 | |
| joseortega | 1:83a13087626e | 18 | int main(){ | 
| joseortega | 1:83a13087626e | 19 | Echo.rise(&start); | 
| joseortega | 1:83a13087626e | 20 | Echo.fall(&stop); | 
| joseortega | 1:83a13087626e | 21 | Trigg=0; | 
| joseortega | 1:83a13087626e | 22 | |
| joseortega | 1:83a13087626e | 23 | while(1){ | 
| joseortega | 1:83a13087626e | 24 | dist=0; | 
| joseortega | 1:83a13087626e | 25 | Trigg=1; | 
| joseortega | 1:83a13087626e | 26 | wait_us(10); | 
| joseortega | 1:83a13087626e | 27 | Trigg=0; | 
| joseortega | 1:83a13087626e | 28 | while(dist==0){ | 
| joseortega | 1:83a13087626e | 29 | wait_us(1); | 
| joseortega | 1:83a13087626e | 30 | |
| joseortega | 1:83a13087626e | 31 | } | 
| joseortega | 1:83a13087626e | 32 | |
| joseortega | 1:83a13087626e | 33 | dist=dist/58.0; | 
| joseortega | 1:83a13087626e | 34 | |
| joseortega | 1:83a13087626e | 35 | |
| joseortega | 1:83a13087626e | 36 | serialpc.printf("distancia %f cm\n",dist); | 
| joseortega | 1:83a13087626e | 37 | wait(.2); | 
| joseortega | 1:83a13087626e | 38 | } | 
| joseortega | 1:83a13087626e | 39 | } |